Skip to content

Commit

Permalink
Integ test fixups (#2460)
Browse files Browse the repository at this point in the history
* Change asserts to require in integ tests

* Copy all test tasks in integ tests to avoid data races

* image manager integ test logging fix

* skipping windows image cleanup test because of hcsshim bug
  • Loading branch information
sparrc authored May 27, 2020
1 parent ef91b76 commit d7d87c6
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 125 deletions.
27 changes: 16 additions & 11 deletions agent/engine/docker_image_manager_integ_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
package engine

import (
"container/list"
"context"
"errors"
"fmt"
"runtime"
"testing"
"time"

Expand Down Expand Up @@ -55,6 +55,11 @@ const (
// e. Image has not passed the ‘hasNoAssociatedContainers’ criteria.
// f. Ensure that that if not eligible, image is not deleted from the instance and image reference in ImageManager is not removed.
func TestIntegImageCleanupHappyCase(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip(`Skipping this test because of error: level=error time=2020-05-27T20:20:03Z msg="Error removing` +
` Image amazon/image-cleanup-test-image2:make - Error response from daemon: hcsshim::GetComputeSystems:` +
` The requested compute system operation is not valid in the current state." module=log.go`)
}
cfg := defaultTestConfigIntegTest()
cfg.TaskCleanupWaitDuration = 5 * time.Second

Expand Down Expand Up @@ -632,29 +637,29 @@ func verifyTaskIsCleanedUp(taskName string, taskEngine TaskEngine) error {
}

func verifyImagesAreRemoved(imageManager *dockerImageManager, imageIDs ...string) error {
imagesNotRemovedList := list.New()
imagesNotRemovedList := []string{}
for _, imageID := range imageIDs {
_, ok := imageManager.getImageState(imageID)
imageState, ok := imageManager.getImageState(imageID)
if ok {
imagesNotRemovedList.PushFront(imageID)
imagesNotRemovedList = append(imagesNotRemovedList, imageState.Image.String())
}
}
if imagesNotRemovedList.Len() > 0 {
return fmt.Errorf("Image states still exist for: %v", imagesNotRemovedList)
if len(imagesNotRemovedList) > 0 {
return fmt.Errorf("Image states still exist for: %s", imagesNotRemovedList)
}
return nil
}

func verifyImagesAreNotRemoved(imageManager *dockerImageManager, imageIDs ...string) error {
imagesRemovedList := list.New()
imagesRemovedList := []string{}
for _, imageID := range imageIDs {
_, ok := imageManager.getImageState(imageID)
imageState, ok := imageManager.getImageState(imageID)
if !ok {
imagesRemovedList.PushFront(imageID)
imagesRemovedList = append(imagesRemovedList, imageState.Image.String())
}
}
if imagesRemovedList.Len() > 0 {
return fmt.Errorf("Could not find images: %v in ImageManager", imagesRemovedList)
if len(imagesRemovedList) > 0 {
return fmt.Errorf("Could not find images: %s in ImageManager", imagesRemovedList)
}
return nil
}
Expand Down
7 changes: 4 additions & 3 deletions agent/engine/engine_integ_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -637,9 +637,10 @@ func TestTaskCleanup(t *testing.T) {
_, err = client.ContainerInspect(ctx, cid)
assert.NoError(t, err, "Inspect should work")

testUpdate := *testTask
testUpdate.SetDesiredStatus(apitaskstatus.TaskStopped)
go taskEngine.AddTask(&testUpdate)
// Create instead of copying the testTask, to avoid race condition.
taskUpdate := createTestTask(testArn)
taskUpdate.SetDesiredStatus(apitaskstatus.TaskStopped)
go taskEngine.AddTask(taskUpdate)
verifyContainerStoppedStateChange(t, taskEngine)
verifyTaskStoppedStateChange(t, taskEngine)

Expand Down
Loading

0 comments on commit d7d87c6

Please sign in to comment.