Skip to content

Commit

Permalink
Fix Windows integration tests (#4304)
Browse files Browse the repository at this point in the history
  • Loading branch information
tinnywang authored Sep 3, 2024
1 parent a876998 commit ad039c2
Show file tree
Hide file tree
Showing 10 changed files with 637 additions and 481 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//go:build integration
// +build integration
//go:build unix && integration
// +build unix,integration

// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
//
Expand Down
31 changes: 31 additions & 0 deletions agent/engine/common_integ_testutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"
"fmt"
"os"
"runtime"
"testing"
"time"

Expand Down Expand Up @@ -143,13 +144,25 @@ func loggerConfigIntegrationTest(logfile string) string {
}

func VerifyContainerManifestPulledStateChange(t *testing.T, taskEngine TaskEngine) {
// Skip assertions on Windows because we don't run a local registry,
// so images are always cached and never pulled.
if runtime.GOOS == "windows" {
t.Log("Not expecting image manifest pulls on Windows")
return
}
stateChangeEvents := taskEngine.StateChangeEvents()
event := <-stateChangeEvents
assert.Equal(t, apicontainerstatus.ContainerManifestPulled, event.(api.ContainerStateChange).Status,
"Expected container to be at MANIFEST_PULLED state")
}

func VerifyTaskManifestPulledStateChange(t *testing.T, taskEngine TaskEngine) {
// Skip assertions on Windows because we don't run a local registry,
// so images are always cached and never pulled.
if runtime.GOOS == "windows" {
t.Log("Not expecting image manifest pulls on Windows")
return
}
stateChangeEvents := taskEngine.StateChangeEvents()
event := <-stateChangeEvents
assert.Equal(t, apitaskstatus.TaskManifestPulled, event.(api.TaskStateChange).Status,
Expand Down Expand Up @@ -222,6 +235,12 @@ func verifyContainerStoppedStateChangeWithRuntimeID(t *testing.T, taskEngine Tas
// has a specific status (identified by the containerStatus parameter)
func verifySpecificContainerStateChange(t *testing.T, taskEngine TaskEngine, containerName string,
containerStatus apicontainerstatus.ContainerStatus) {
// Skip assertions on Windows because we don't run a local registry,
// so images are always cached and never pulled.
if runtime.GOOS == "windows" && containerStatus == apicontainerstatus.ContainerManifestPulled {
t.Log("Not expecting image manifest pulls on Windows")
return
}
stateChangeEvents := taskEngine.StateChangeEvents()
event := <-stateChangeEvents
assert.Equal(t, event.(api.ContainerStateChange).ContainerName, containerName)
Expand Down Expand Up @@ -343,6 +362,12 @@ func InitTestEventCollection(taskEngine TaskEngine) *TestEvents {
// This method queries the TestEvents struct to check a Task Status.
// This method will block if there are no more stateChangeEvents from the DockerTaskEngine but is expected
func VerifyTaskStatus(status apitaskstatus.TaskStatus, taskARN string, testEvents *TestEvents, t *testing.T) {
// Skip assertions on Windows because we don't run a local registry,
// so images are always cached and never pulled.
if runtime.GOOS == "windows" && status == apitaskstatus.TaskManifestPulled {
t.Log("Not expecting image manifest pulls on Windows")
return
}
for {
if _, found := testEvents.RecordedEvents[statechange.TaskEvent][status.String()][taskARN]; found {
return
Expand All @@ -355,6 +380,12 @@ func VerifyTaskStatus(status apitaskstatus.TaskStatus, taskARN string, testEvent
// This method queries the TestEvents struct to check a Task Status.
// This method will block if there are no more stateChangeEvents from the DockerTaskEngine but is expected
func VerifyContainerStatus(status apicontainerstatus.ContainerStatus, ARNcontName string, testEvents *TestEvents, t *testing.T) {
// Skip assertions on Windows because we don't run a local registry,
// so images are always cached and never pulled.
if runtime.GOOS == "windows" && status == apicontainerstatus.ContainerManifestPulled {
t.Log("Not expecting image manifest pulls on Windows")
return
}
for {
if _, found := testEvents.RecordedEvents[statechange.ContainerEvent][status.String()][ARNcontName]; found {
return
Expand Down
51 changes: 51 additions & 0 deletions agent/engine/common_windows_integ_testutil.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
//go:build windows && (sudo || integration)
// +build windows
// +build sudo integration

// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License"). You may
// not use this file except in compliance with the License. A copy of the
// License is located at
//
// http://aws.amazon.com/apache2.0/
//
// or in the "license" file accompanying this file. This file is distributed
// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
// express or implied. See the License for the specific language governing
// permissions and limitations under the License.

package engine

import (
"os"

apicontainer "github.com/aws/amazon-ecs-agent/agent/api/container"
)

const (
testBaseImage = "amazon-ecs-ftest-windows-base:make"
dockerEndpoint = "npipe:////./pipe/docker_engine"
)

// REGISTRY_IMAGE_NAME is the Windows Server image from Microsoft Container Registry.
// https://github.com/aws/amazon-ecs-agent/blob/78a2bf0c7d3ebd3a13de3ac733af46dfb3816b18/scripts/run-integ-tests.ps1#L45
var (
testRegistryImage = os.Getenv("REGISTRY_IMAGE_NAME")
testRegistryImageWithDigest = os.Getenv("REGISTRY_IMAGE_NAME_WITH_DIGEST")
)

func CreateTestContainer() *apicontainer.Container {
return createTestContainerWithImageAndName(testBaseImage, "windows")
}

// GetLongRunningCommand returns the command that keeps the container running for the container
// that uses the default integ test image (amazon-ecs-ftest-windows-base:make for windows)
func GetLongRunningCommand() []string {
return []string{"ping", "-t", "localhost"}
}

func isDockerRunning() bool {
_, err := os.Stat("//./pipe/docker_engine")
return err == nil
}
Loading

0 comments on commit ad039c2

Please sign in to comment.