mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
integration-cli: move goroutines info helpers to separate funcs
Signed-off-by: Alexander Morozov <lk4d4@docker.com>
This commit is contained in:
parent
90ce409e35
commit
0c7c9df804
3 changed files with 51 additions and 84 deletions
|
@ -1,7 +1,6 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
@ -265,20 +264,8 @@ func (s *DockerSuite) TestLogsFollowGoroutinesWithStdout(c *check.C) {
|
||||||
id := strings.TrimSpace(out)
|
id := strings.TrimSpace(out)
|
||||||
c.Assert(waitRun(id), checker.IsNil)
|
c.Assert(waitRun(id), checker.IsNil)
|
||||||
|
|
||||||
type info struct {
|
nroutines, err := getGoroutineNumber()
|
||||||
NGoroutines int
|
|
||||||
}
|
|
||||||
getNGoroutines := func() int {
|
|
||||||
var i info
|
|
||||||
status, b, err := sockRequest("GET", "/info", nil)
|
|
||||||
c.Assert(err, checker.IsNil)
|
c.Assert(err, checker.IsNil)
|
||||||
c.Assert(status, checker.Equals, 200)
|
|
||||||
c.Assert(json.Unmarshal(b, &i), checker.IsNil)
|
|
||||||
return i.NGoroutines
|
|
||||||
}
|
|
||||||
|
|
||||||
nroutines := getNGoroutines()
|
|
||||||
|
|
||||||
cmd := exec.Command(dockerBinary, "logs", "-f", id)
|
cmd := exec.Command(dockerBinary, "logs", "-f", id)
|
||||||
r, w := io.Pipe()
|
r, w := io.Pipe()
|
||||||
cmd.Stdout = w
|
cmd.Stdout = w
|
||||||
|
@ -295,20 +282,7 @@ func (s *DockerSuite) TestLogsFollowGoroutinesWithStdout(c *check.C) {
|
||||||
c.Assert(cmd.Process.Kill(), checker.IsNil)
|
c.Assert(cmd.Process.Kill(), checker.IsNil)
|
||||||
|
|
||||||
// NGoroutines is not updated right away, so we need to wait before failing
|
// NGoroutines is not updated right away, so we need to wait before failing
|
||||||
t := time.After(30 * time.Second)
|
c.Assert(waitForGoroutines(nroutines), checker.IsNil)
|
||||||
for {
|
|
||||||
select {
|
|
||||||
case <-t:
|
|
||||||
n := getNGoroutines()
|
|
||||||
c.Assert(n <= nroutines, checker.Equals, true, check.Commentf("leaked goroutines: expected less than or equal to %d, got: %d", nroutines, n))
|
|
||||||
|
|
||||||
default:
|
|
||||||
if n := getNGoroutines(); n <= nroutines {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
time.Sleep(200 * time.Millisecond)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DockerSuite) TestLogsFollowGoroutinesNoOutput(c *check.C) {
|
func (s *DockerSuite) TestLogsFollowGoroutinesNoOutput(c *check.C) {
|
||||||
|
@ -316,40 +290,15 @@ func (s *DockerSuite) TestLogsFollowGoroutinesNoOutput(c *check.C) {
|
||||||
id := strings.TrimSpace(out)
|
id := strings.TrimSpace(out)
|
||||||
c.Assert(waitRun(id), checker.IsNil)
|
c.Assert(waitRun(id), checker.IsNil)
|
||||||
|
|
||||||
type info struct {
|
nroutines, err := getGoroutineNumber()
|
||||||
NGoroutines int
|
|
||||||
}
|
|
||||||
getNGoroutines := func() int {
|
|
||||||
var i info
|
|
||||||
status, b, err := sockRequest("GET", "/info", nil)
|
|
||||||
c.Assert(err, checker.IsNil)
|
c.Assert(err, checker.IsNil)
|
||||||
c.Assert(status, checker.Equals, 200)
|
|
||||||
c.Assert(json.Unmarshal(b, &i), checker.IsNil)
|
|
||||||
return i.NGoroutines
|
|
||||||
}
|
|
||||||
|
|
||||||
nroutines := getNGoroutines()
|
|
||||||
|
|
||||||
cmd := exec.Command(dockerBinary, "logs", "-f", id)
|
cmd := exec.Command(dockerBinary, "logs", "-f", id)
|
||||||
c.Assert(cmd.Start(), checker.IsNil)
|
c.Assert(cmd.Start(), checker.IsNil)
|
||||||
time.Sleep(200 * time.Millisecond)
|
time.Sleep(200 * time.Millisecond)
|
||||||
c.Assert(cmd.Process.Kill(), checker.IsNil)
|
c.Assert(cmd.Process.Kill(), checker.IsNil)
|
||||||
|
|
||||||
// NGoroutines is not updated right away, so we need to wait before failing
|
// NGoroutines is not updated right away, so we need to wait before failing
|
||||||
t := time.After(30 * time.Second)
|
c.Assert(waitForGoroutines(nroutines), checker.IsNil)
|
||||||
for {
|
|
||||||
select {
|
|
||||||
case <-t:
|
|
||||||
n := getNGoroutines()
|
|
||||||
c.Assert(n <= nroutines, checker.Equals, true, check.Commentf("leaked goroutines: expected less than or equal to %d, got: %d", nroutines, n))
|
|
||||||
|
|
||||||
default:
|
|
||||||
if n := getNGoroutines(); n <= nroutines {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
time.Sleep(200 * time.Millisecond)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DockerSuite) TestLogsCLIContainerNotFound(c *check.C) {
|
func (s *DockerSuite) TestLogsCLIContainerNotFound(c *check.C) {
|
||||||
|
|
|
@ -3,7 +3,6 @@ package main
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net"
|
"net"
|
||||||
|
@ -4223,18 +4222,8 @@ func (s *DockerSuite) TestRunNamedVolumesFromNotRemoved(c *check.C) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DockerSuite) TestRunAttachFailedNoLeak(c *check.C) {
|
func (s *DockerSuite) TestRunAttachFailedNoLeak(c *check.C) {
|
||||||
type info struct {
|
nroutines, err := getGoroutineNumber()
|
||||||
NGoroutines int
|
|
||||||
}
|
|
||||||
getNGoroutines := func() int {
|
|
||||||
var i info
|
|
||||||
status, b, err := sockRequest("GET", "/info", nil)
|
|
||||||
c.Assert(err, checker.IsNil)
|
c.Assert(err, checker.IsNil)
|
||||||
c.Assert(status, checker.Equals, 200)
|
|
||||||
c.Assert(json.Unmarshal(b, &i), checker.IsNil)
|
|
||||||
return i.NGoroutines
|
|
||||||
}
|
|
||||||
nroutines := getNGoroutines()
|
|
||||||
|
|
||||||
runSleepingContainer(c, "--name=test", "-p", "8000:8000")
|
runSleepingContainer(c, "--name=test", "-p", "8000:8000")
|
||||||
|
|
||||||
|
@ -4245,18 +4234,5 @@ func (s *DockerSuite) TestRunAttachFailedNoLeak(c *check.C) {
|
||||||
dockerCmd(c, "rm", "-f", "test")
|
dockerCmd(c, "rm", "-f", "test")
|
||||||
|
|
||||||
// NGoroutines is not updated right away, so we need to wait before failing
|
// NGoroutines is not updated right away, so we need to wait before failing
|
||||||
t := time.After(30 * time.Second)
|
c.Assert(waitForGoroutines(nroutines), checker.IsNil)
|
||||||
for {
|
|
||||||
select {
|
|
||||||
case <-t:
|
|
||||||
n := getNGoroutines()
|
|
||||||
c.Assert(n <= nroutines, checker.Equals, true, check.Commentf("leaked goroutines: expected less than or equal to %d, got: %d", nroutines, n))
|
|
||||||
|
|
||||||
default:
|
|
||||||
if n := getNGoroutines(); n <= nroutines {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
time.Sleep(200 * time.Millisecond)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1435,3 +1435,45 @@ func minimalBaseImage() string {
|
||||||
}
|
}
|
||||||
return "scratch"
|
return "scratch"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getGoroutineNumber() (int, error) {
|
||||||
|
i := struct {
|
||||||
|
NGoroutines int
|
||||||
|
}{}
|
||||||
|
status, b, err := sockRequest("GET", "/info", nil)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
if status != http.StatusOK {
|
||||||
|
return 0, fmt.Errorf("http status code: %d", status)
|
||||||
|
}
|
||||||
|
if err := json.Unmarshal(b, &i); err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
return i.NGoroutines, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func waitForGoroutines(expected int) error {
|
||||||
|
t := time.After(30 * time.Second)
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case <-t:
|
||||||
|
n, err := getGoroutineNumber()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if n > expected {
|
||||||
|
return fmt.Errorf("leaked goroutines: expected less than or equal to %d, got: %d", expected, n)
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
n, err := getGoroutineNumber()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if n <= expected {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
time.Sleep(200 * time.Millisecond)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue