1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Optimize slow integration test

Optimize `TestEventsOOMDisableTrue` performance

It's part of #19425 issue.

Signed-off-by: Zhang Wei <zhangwei555@huawei.com>
This commit is contained in:
Zhang Wei 2016-01-24 11:27:39 +08:00
parent bf85a49509
commit 6bf5b3db9a

View file

@ -79,6 +79,12 @@ func (s *DockerSuite) TestEventsOOMDisableTrue(c *check.C) {
testRequires(c, DaemonIsLinux, oomControl, memoryLimitSupport, NotGCCGO, NotArm) testRequires(c, DaemonIsLinux, oomControl, memoryLimitSupport, NotGCCGO, NotArm)
errChan := make(chan error) errChan := make(chan error)
observer, err := newEventObserver(c)
c.Assert(err, checker.IsNil)
err = observer.Start()
c.Assert(err, checker.IsNil)
defer observer.Stop()
go func() { go func() {
defer close(errChan) defer close(errChan)
out, exitCode, _ := dockerCmdWithError("run", "--oom-kill-disable=true", "--name", "oomTrue", "-m", "10MB", "busybox", "sh", "-c", "x=a; while true; do x=$x$x$x$x; done") out, exitCode, _ := dockerCmdWithError("run", "--oom-kill-disable=true", "--name", "oomTrue", "-m", "10MB", "busybox", "sh", "-c", "x=a; while true; do x=$x$x$x$x; done")
@ -86,25 +92,36 @@ func (s *DockerSuite) TestEventsOOMDisableTrue(c *check.C) {
errChan <- fmt.Errorf("wrong exit code for OOM container: expected %d, got %d (output: %q)", expected, exitCode, out) errChan <- fmt.Errorf("wrong exit code for OOM container: expected %d, got %d (output: %q)", expected, exitCode, out)
} }
}() }()
select {
case err := <-errChan: c.Assert(waitRun("oomTrue"), checker.IsNil)
c.Assert(err, checker.IsNil)
case <-time.After(20 * time.Second):
defer dockerCmd(c, "kill", "oomTrue") defer dockerCmd(c, "kill", "oomTrue")
containerID, err := inspectField("oomTrue", "Id")
c.Assert(err, checker.IsNil)
out, _ := dockerCmd(c, "events", "--since=0", "-f", "container=oomTrue", fmt.Sprintf("--until=%d", daemonTime(c).Unix())) testActions := map[string]chan bool{
events := strings.Split(strings.TrimSuffix(out, "\n"), "\n") "oom": make(chan bool),
nEvents := len(events)
c.Assert(nEvents, checker.GreaterOrEqualThan, 4) //Missing expected event
c.Assert(parseEventAction(c, events[nEvents-4]), checker.Equals, "create")
c.Assert(parseEventAction(c, events[nEvents-3]), checker.Equals, "attach")
c.Assert(parseEventAction(c, events[nEvents-2]), checker.Equals, "start")
c.Assert(parseEventAction(c, events[nEvents-1]), checker.Equals, "oom")
out, _ = dockerCmd(c, "inspect", "-f", "{{.State.Status}}", "oomTrue")
c.Assert(strings.TrimSpace(out), checker.Equals, "running", check.Commentf("container should be still running"))
} }
matcher := matchEventLine(containerID, "container", testActions)
processor := processEventMatch(testActions)
go observer.Match(matcher, processor)
select {
case <-time.After(20 * time.Second):
observer.CheckEventError(c, containerID, "oom", matcher)
case <-testActions["oom"]:
// ignore, done
case errRun := <-errChan:
if errRun != nil {
c.Fatalf("%v", errRun)
} else {
c.Fatalf("container should be still running but it's not")
}
}
status, err := inspectField("oomTrue", "State.Status")
c.Assert(err, checker.IsNil)
c.Assert(strings.TrimSpace(status), checker.Equals, "running", check.Commentf("container should be still running"))
} }
// #18453 // #18453