Signed-off-by: Brian Goff <cpuguy83@gmail.com>
| ... | ... |
@@ -416,22 +416,30 @@ func (s *DockerSuite) TestGetContainerStatsNoStream(c *check.C) {
|
| 416 | 416 |
func (s *DockerSuite) TestGetStoppedContainerStats(c *check.C) {
|
| 417 | 417 |
// Problematic on Windows as Windows does not support stats |
| 418 | 418 |
testRequires(c, DaemonIsLinux) |
| 419 |
- // TODO: this test does nothing because we are c.Assert'ing in goroutine |
|
| 420 |
- var ( |
|
| 421 |
- name = "statscontainer" |
|
| 422 |
- ) |
|
| 419 |
+ name := "statscontainer" |
|
| 423 | 420 |
dockerCmd(c, "create", "--name", name, "busybox", "top") |
| 424 | 421 |
|
| 422 |
+ type stats struct {
|
|
| 423 |
+ status int |
|
| 424 |
+ err error |
|
| 425 |
+ } |
|
| 426 |
+ chResp := make(chan stats) |
|
| 427 |
+ |
|
| 428 |
+ // We expect an immediate response, but if it's not immediate, the test would hang, so put it in a goroutine |
|
| 429 |
+ // below we'll check this on a timeout. |
|
| 425 | 430 |
go func() {
|
| 426 |
- // We'll never get return for GET stats from sockRequest as of now, |
|
| 427 |
- // just send request and see if panic or error would happen on daemon side. |
|
| 428 |
- status, _, err := sockRequest("GET", "/containers/"+name+"/stats", nil)
|
|
| 429 |
- c.Assert(err, checker.IsNil) |
|
| 430 |
- c.Assert(status, checker.Equals, http.StatusOK) |
|
| 431 |
+ resp, body, err := sockRequestRaw("GET", "/containers/"+name+"/stats", nil, "")
|
|
| 432 |
+ body.Close() |
|
| 433 |
+ chResp <- stats{resp.StatusCode, err}
|
|
| 431 | 434 |
}() |
| 432 | 435 |
|
| 433 |
- // allow some time to send request and let daemon deal with it |
|
| 434 |
- time.Sleep(1 * time.Second) |
|
| 436 |
+ select {
|
|
| 437 |
+ case r := <-chResp: |
|
| 438 |
+ c.Assert(r.err, checker.IsNil) |
|
| 439 |
+ c.Assert(r.status, checker.Equals, http.StatusOK) |
|
| 440 |
+ case <-time.After(10 * time.Second): |
|
| 441 |
+ c.Fatal("timeout waiting for stats reponse for stopped container")
|
|
| 442 |
+ } |
|
| 435 | 443 |
} |
| 436 | 444 |
|
| 437 | 445 |
// #9981 - Allow a docker created volume (ie, one in /var/lib/docker/volumes) to be used to overwrite (via passing in Binds on api start) an existing volume |