Skip to content

Commit

Permalink
Fix TestDockerStateToContainerState integ test.
Browse files Browse the repository at this point in the history
During the workflow of TestDockerStateToContainerState, it starts a container and checks whether it's running by inspecting it. However, the container it starts exit immediately, so it's possible that when we check whether the container is running it's already stopped. This leads to flakey test as per #1899. Fixing by letting the container keep running rather than exit itself.
  • Loading branch information
fenxiong committed Mar 7, 2019
1 parent 6744fa0 commit 08d3eaf
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
6 changes: 6 additions & 0 deletions agent/engine/common_unix_integ_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ func createTestContainer() *apicontainer.Container {
return createTestContainerWithImageAndName(testRegistryImage, "netcat")
}

// getLongRunningCommand returns the command that keeps the container running for the container
// that uses the default integ test image (amazon/amazon-ecs-netkitten for unix)
func getLongRunningCommand() []string {
return []string{"-loop=true"}
}

func isDockerRunning() bool {
_, err := os.Stat("/var/run/docker.sock")
return err == nil
Expand Down
4 changes: 4 additions & 0 deletions agent/engine/engine_integ_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ func TestDockerStateToContainerState(t *testing.T) {
testTask := createTestTask("test_task")
container := testTask.Containers[0]

// let the container keep running to prevent the edge case where it's already stopped when we check whether
// it's running
container.Command = getLongRunningCommand()

client, err := sdkClient.NewClientWithOpts(sdkClient.WithHost(endpoint), sdkClient.WithVersion(sdkclientfactory.GetDefaultVersion().String()))
require.NoError(t, err, "Creating go docker client failed")

Expand Down
6 changes: 6 additions & 0 deletions agent/engine/engine_windows_integ_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ func createTestContainer() *apicontainer.Container {
}
}

// getLongRunningCommand returns the command that keeps the container running for the container
// that uses the default integ test image (microsoft/windowsservercore for windows)
func getLongRunningCommand() []string {
return []string{"ping", "-t", "localhost"}
}

func createTestHostVolumeMountTask(tmpPath string) *apitask.Task {
testTask := createTestTask("testHostVolumeMount")
testTask.Volumes = []apitask.TaskVolume{{Name: "test-tmp", Volume: &taskresourcevolume.FSHostVolume{FSSourcePath: tmpPath}}}
Expand Down

0 comments on commit 08d3eaf

Please sign in to comment.