mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
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 <fabio.kung@gmail.com>
This commit is contained in:
parent
aacddda89d
commit
fcb6d37a8d
1 changed files with 6 additions and 2 deletions
|
@ -4,6 +4,7 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
|
@ -50,14 +51,17 @@ func getPausedContainers(t testingT, dockerBinary string) []string {
|
||||||
return strings.Fields(result.Combined())
|
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) {
|
func deleteAllContainers(t testingT, dockerBinary string) {
|
||||||
containers := getAllContainers(t, dockerBinary)
|
containers := getAllContainers(t, dockerBinary)
|
||||||
if len(containers) > 0 {
|
if len(containers) > 0 {
|
||||||
result := icmd.RunCommand(dockerBinary, append([]string{"rm", "-fv"}, containers...)...)
|
result := icmd.RunCommand(dockerBinary, append([]string{"rm", "-fv"}, containers...)...)
|
||||||
if result.Error != nil {
|
if result.Error != nil {
|
||||||
// If the error is "No such container: ..." this means the container doesn't exists anymore,
|
// If the error is "No such container: ..." this means the container doesn't exists anymore,
|
||||||
// we can safely ignore that one.
|
// or if it is "... removal of container ... is already in progress" it will be removed eventually.
|
||||||
if strings.Contains(result.Stderr(), "No such container") {
|
// We can safely ignore those.
|
||||||
|
if strings.Contains(result.Stderr(), "No such container") || alreadyExists.MatchString(result.Stderr()) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
t.Fatalf("error removing containers %v : %v (%s)", containers, result.Error, result.Combined())
|
t.Fatalf("error removing containers %v : %v (%s)", containers, result.Error, result.Combined())
|
||||||
|
|
Loading…
Add table
Reference in a new issue