From fcb6d37a8dde8a91896116742116e9d9808b18ac Mon Sep 17 00:00:00 2001 From: Fabio Kung Date: Fri, 10 Mar 2017 21:06:05 -0800 Subject: [PATCH] Make tests a bit less flaky Prevent tests failing when teardown tries to delete a container that is already being removed. Signed-off-by: Fabio Kung --- integration-cli/environment/clean.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/integration-cli/environment/clean.go b/integration-cli/environment/clean.go index b27838337e..809baa7b52 100644 --- a/integration-cli/environment/clean.go +++ b/integration-cli/environment/clean.go @@ -4,6 +4,7 @@ import ( "encoding/json" "fmt" "net/http" + "regexp" "strings" "github.com/docker/docker/api/types" @@ -50,14 +51,17 @@ func getPausedContainers(t testingT, dockerBinary string) []string { return strings.Fields(result.Combined()) } +var alreadyExists = regexp.MustCompile(`Error response from daemon: removal of container (\w+) is already in progress`) + func deleteAllContainers(t testingT, dockerBinary string) { containers := getAllContainers(t, dockerBinary) if len(containers) > 0 { result := icmd.RunCommand(dockerBinary, append([]string{"rm", "-fv"}, containers...)...) if result.Error != nil { // If the error is "No such container: ..." this means the container doesn't exists anymore, - // we can safely ignore that one. - if strings.Contains(result.Stderr(), "No such container") { + // or if it is "... removal of container ... is already in progress" it will be removed eventually. + // We can safely ignore those. + if strings.Contains(result.Stderr(), "No such container") || alreadyExists.MatchString(result.Stderr()) { return } t.Fatalf("error removing containers %v : %v (%s)", containers, result.Error, result.Combined())