mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #14359 from cpuguy83/14354_events_send_resp_immediately
Send resp immediately on GET /events
This commit is contained in:
commit
71f8ca30ce
2 changed files with 32 additions and 1 deletions
|
@ -430,7 +430,9 @@ func (s *Server) getEvents(version version.Version, w http.ResponseWriter, r *ht
|
||||||
d := s.daemon
|
d := s.daemon
|
||||||
es := d.EventsService
|
es := d.EventsService
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
enc := json.NewEncoder(ioutils.NewWriteFlusher(w))
|
outStream := ioutils.NewWriteFlusher(w)
|
||||||
|
outStream.Write(nil) // make sure response is sent immediately
|
||||||
|
enc := json.NewEncoder(outStream)
|
||||||
|
|
||||||
getContainerId := func(cn string) string {
|
getContainerId := func(cn string) string {
|
||||||
c, err := d.Get(cn)
|
c, err := d.Get(cn)
|
||||||
|
|
29
integration-cli/docker_api_events_test.go
Normal file
29
integration-cli/docker_api_events_test.go
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/go-check/check"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (s *DockerSuite) TestEventsApiEmptyOutput(c *check.C) {
|
||||||
|
type apiResp struct {
|
||||||
|
resp *http.Response
|
||||||
|
err error
|
||||||
|
}
|
||||||
|
chResp := make(chan *apiResp)
|
||||||
|
go func() {
|
||||||
|
resp, body, err := sockRequestRaw("GET", "/events", nil, "")
|
||||||
|
body.Close()
|
||||||
|
chResp <- &apiResp{resp, err}
|
||||||
|
}()
|
||||||
|
|
||||||
|
select {
|
||||||
|
case r := <-chResp:
|
||||||
|
c.Assert(r.err, check.IsNil)
|
||||||
|
c.Assert(r.resp.StatusCode, check.Equals, http.StatusOK)
|
||||||
|
case <-time.After(3 * time.Second):
|
||||||
|
c.Fatal("timeout waiting for events api to respond, should have responded immediately")
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue