Skip to content

Commit

Permalink
Cleaning up volumes after test completes
Browse files Browse the repository at this point in the history
  • Loading branch information
linkar-ec2 committed Oct 9, 2018
1 parent fa8f17b commit d888811
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
14 changes: 14 additions & 0 deletions agent/engine/engine_integ_test.go
Expand Up @@ -48,6 +48,7 @@ const (
dialTimeout = 200 * time.Millisecond
localhost = "127.0.0.1"
waitForDockerDuration = 50 * time.Millisecond
removeVolumeTimeout = 5 * time.Second
)

func init() {
Expand Down Expand Up @@ -96,6 +97,13 @@ func removeImage(t *testing.T, img string) {
client.RemoveImage(img)
}

func cleanVolumes(testTask *apitask.Task, taskEngine TaskEngine) {
client := taskEngine.(*DockerTaskEngine).client
for _, aVolume := range testTask.Volumes {
client.RemoveVolume(context.TODO(), aVolume.Name, removeVolumeTimeout)
}
}

// TestDockerStateToContainerState tests convert the container status from
// docker inspect to the status defined in agent
func TestDockerStateToContainerState(t *testing.T) {
Expand Down Expand Up @@ -169,6 +177,8 @@ func TestHostVolumeMount(t *testing.T) {
data, err := ioutil.ReadFile(filepath.Join(tmpPath, "hello-from-container"))
assert.Nil(t, err, "Unexpected error")
assert.Equal(t, "hi", strings.TrimSpace(string(data)), "Incorrect file contents")

cleanVolumes(testTask, taskEngine)
}

func TestSweepContainer(t *testing.T) {
Expand Down Expand Up @@ -379,6 +389,8 @@ func TestSharedAutoprovisionVolume(t *testing.T) {
client := taskEngine.(*DockerTaskEngine).client
response := client.InspectVolume(context.TODO(), "TestSharedAutoprovisionVolume", 1*time.Second)
assert.NoError(t, response.Error, "expect shared volume not removed")

cleanVolumes(testTask, taskEngine)
}

func TestSharedDoNotAutoprovisionVolume(t *testing.T) {
Expand Down Expand Up @@ -410,4 +422,6 @@ func TestSharedDoNotAutoprovisionVolume(t *testing.T) {
waitForTaskCleanup(t, taskEngine, testTask.Arn, 5)
response := client.InspectVolume(context.TODO(), "TestSharedDoNotAutoprovisionVolume", 1*time.Second)
assert.NoError(t, response.Error, "expect shared volume not removed")

cleanVolumes(testTask, taskEngine)
}
4 changes: 4 additions & 0 deletions agent/engine/engine_unix_integ_test.go
Expand Up @@ -16,6 +16,7 @@
package engine

import (
"context"
"encoding/base64"
"fmt"
"io/ioutil"
Expand Down Expand Up @@ -838,4 +839,7 @@ func TestTaskLevelVolume(t *testing.T) {
verifyTaskIsStopped(stateChangeEvents, testTask)
assert.Equal(t, *testTask.Containers[0].GetKnownExitCode(), 0)
assert.NotEqual(t, testTask.ResourcesMapUnsafe["dockerVolume"][0].(*taskresourcevolume.VolumeResource).VolumeConfig.Source(), "TestTaskLevelVolume", "task volume name is the same as specified in task definition")

client := taskEngine.(*DockerTaskEngine).client
client.RemoveVolume(context.TODO(), "TestTaskLevelVolume", 5*time.Second)
}

0 comments on commit d888811

Please sign in to comment.