Skip to content

Commit

Permalink
Merge pull request moby#14359 from cpuguy83/14354_events_send_resp_im…
Browse files Browse the repository at this point in the history
…mediately

Send resp immediately on GET /events
  • Loading branch information
calavera committed Jul 2, 2015
2 parents f0ed68f + d0a299c commit 71f8ca3
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
4 changes: 3 additions & 1 deletion api/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,9 @@ func (s *Server) getEvents(version version.Version, w http.ResponseWriter, r *ht
d := s.daemon
es := d.EventsService
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 {
c, err := d.Get(cn)
Expand Down
29 changes: 29 additions & 0 deletions integration-cli/docker_api_events_test.go
Original file line number Diff line number Diff line change
@@ -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")
}
}

0 comments on commit 71f8ca3

Please sign in to comment.