mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
fix race in events test
Docker-DCO-1.1-Signed-off-by: Jessie Frazelle <jess@docker.com> (github: jfrazelle)
This commit is contained in:
parent
934535db9c
commit
27c61c39db
1 changed files with 20 additions and 12 deletions
|
@ -127,7 +127,7 @@ func TestEventsImageUntagDelete(t *testing.T) {
|
||||||
t.Fatalf("Failed to get events with exit code %d: %s", exitCode, err)
|
t.Fatalf("Failed to get events with exit code %d: %s", exitCode, err)
|
||||||
}
|
}
|
||||||
events := strings.Split(out, "\n")
|
events := strings.Split(out, "\n")
|
||||||
t.Log(events)
|
|
||||||
events = events[:len(events)-1]
|
events = events[:len(events)-1]
|
||||||
if len(events) < 2 {
|
if len(events) < 2 {
|
||||||
t.Fatalf("Missing expected event")
|
t.Fatalf("Missing expected event")
|
||||||
|
@ -169,6 +169,7 @@ func TestEventsImagePull(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEventsImageImport(t *testing.T) {
|
func TestEventsImageImport(t *testing.T) {
|
||||||
|
defer deleteAllContainers()
|
||||||
since := time.Now().Unix()
|
since := time.Now().Unix()
|
||||||
|
|
||||||
runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "true")
|
runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "true")
|
||||||
|
@ -177,7 +178,6 @@ func TestEventsImageImport(t *testing.T) {
|
||||||
t.Fatal("failed to create a container", out, err)
|
t.Fatal("failed to create a container", out, err)
|
||||||
}
|
}
|
||||||
cleanedContainerID := stripTrailingCharacters(out)
|
cleanedContainerID := stripTrailingCharacters(out)
|
||||||
defer deleteContainer(cleanedContainerID)
|
|
||||||
|
|
||||||
out, _, err = runCommandPipelineWithOutput(
|
out, _, err = runCommandPipelineWithOutput(
|
||||||
exec.Command(dockerBinary, "export", cleanedContainerID),
|
exec.Command(dockerBinary, "export", cleanedContainerID),
|
||||||
|
@ -203,19 +203,28 @@ func TestEventsImageImport(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEventsFilters(t *testing.T) {
|
func TestEventsFilters(t *testing.T) {
|
||||||
|
// we need a new daemon here
|
||||||
|
// otherwise events picks up the container from the previous
|
||||||
|
// function as a die event (some sort of race)
|
||||||
|
// I am not proud of this - jessfraz
|
||||||
|
d := NewDaemon(t)
|
||||||
|
if err := d.StartWithBusybox(); err != nil {
|
||||||
|
t.Fatalf("Could not start daemon with busybox: %v", err)
|
||||||
|
}
|
||||||
|
defer d.Stop()
|
||||||
|
|
||||||
since := time.Now().Unix()
|
since := time.Now().Unix()
|
||||||
out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "--rm", "busybox", "true"))
|
out, err := d.Cmd("run", "--rm", "busybox", "true")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(out, err)
|
t.Fatal(out, err)
|
||||||
}
|
}
|
||||||
out, _, err = runCommandWithOutput(exec.Command(dockerBinary, "run", "--rm", "busybox", "true"))
|
out, err = d.Cmd("run", "--rm", "busybox", "true")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(out, err)
|
t.Fatal(out, err)
|
||||||
}
|
}
|
||||||
eventsCmd := exec.Command(dockerBinary, "events", fmt.Sprintf("--since=%d", since), fmt.Sprintf("--until=%d", time.Now().Unix()), "--filter", "event=die")
|
out, err = d.Cmd("events", fmt.Sprintf("--since=%d", since), fmt.Sprintf("--until=%d", time.Now().Unix()), "--filter", "event=die")
|
||||||
out, exitCode, err := runCommandWithOutput(eventsCmd)
|
if err != nil {
|
||||||
if exitCode != 0 || err != nil {
|
t.Fatalf("Failed to get events: %s", err)
|
||||||
t.Fatalf("Failed to get events with exit code %d: %s", exitCode, err)
|
|
||||||
}
|
}
|
||||||
events := strings.Split(out, "\n")
|
events := strings.Split(out, "\n")
|
||||||
events = events[:len(events)-1]
|
events = events[:len(events)-1]
|
||||||
|
@ -232,10 +241,9 @@ func TestEventsFilters(t *testing.T) {
|
||||||
t.Fatalf("event should be die, not %#v", dieEvent)
|
t.Fatalf("event should be die, not %#v", dieEvent)
|
||||||
}
|
}
|
||||||
|
|
||||||
eventsCmd = exec.Command(dockerBinary, "events", fmt.Sprintf("--since=%d", since), fmt.Sprintf("--until=%d", time.Now().Unix()), "--filter", "event=die", "--filter", "event=start")
|
out, err = d.Cmd("events", fmt.Sprintf("--since=%d", since), fmt.Sprintf("--until=%d", time.Now().Unix()), "--filter", "event=die", "--filter", "event=start")
|
||||||
out, exitCode, err = runCommandWithOutput(eventsCmd)
|
if err != nil {
|
||||||
if exitCode != 0 || err != nil {
|
t.Fatalf("Failed to get events: %s", err)
|
||||||
t.Fatalf("Failed to get events with exit code %d: %s", exitCode, err)
|
|
||||||
}
|
}
|
||||||
events = strings.Split(out, "\n")
|
events = strings.Split(out, "\n")
|
||||||
events = events[:len(events)-1]
|
events = events[:len(events)-1]
|
||||||
|
|
Loading…
Reference in a new issue