1
0
Fork 0
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:
David Calavera 2015-07-02 12:00:45 -07:00
commit 71f8ca30ce
2 changed files with 32 additions and 1 deletions

View file

@ -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)

View 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")
}
}