Skip to content

Commit

Permalink
Update Windows test
Browse files Browse the repository at this point in the history
  • Loading branch information
amogh09 committed Aug 15, 2024
1 parent bfb90d0 commit 3372923
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 13 deletions.
36 changes: 32 additions & 4 deletions agent/engine/docker_task_engine_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -859,6 +859,19 @@ func TestPauseContainerHappyPath(t *testing.T) {
dockerClient.EXPECT().ContainerEvents(gomock.Any()).Return(eventStream, nil)
serviceConnectManager.EXPECT().GetAppnetContainerTarballDir().AnyTimes()

// A function to assert that the network pause container in the task is in
// ContainerResourcesProvisioned state. This will be used by dockerClient mock later.
assertPauseContainerIsRunning := func() {
assert.Len(t, sleepTask.Containers, 3, "expected pause container to be populated")
pauseContainer := sleepTask.Containers[2]
assert.Equal(t, apitask.NetworkPauseContainerName, pauseContainer.Name)
assert.Equal(t, apicontainer.ContainerCNIPause, pauseContainer.Type)
assert.Equal(t,
apicontainerstatus.ContainerResourcesProvisioned,
pauseContainer.GetKnownStatus(),
"expected pause container to be running before image repository is called")
}

sleepContainerID1 := containerID + "1"
sleepContainerID2 := containerID + "2"
pauseContainerID := "pauseContainerID"
Expand All @@ -872,8 +885,13 @@ func TestPauseContainerHappyPath(t *testing.T) {
assert.True(t, ok)
assert.Equal(t, apitask.NetworkPauseContainerName, name)
}).Return(dockerapi.DockerContainerMetadata{DockerID: "pauseContainerID"}),
dockerClient.EXPECT().StartContainer(gomock.Any(), pauseContainerID, defaultConfig.ContainerStartTimeout).Return(
dockerapi.DockerContainerMetadata{DockerID: "pauseContainerID"}),
dockerClient.EXPECT().
StartContainer(gomock.Any(), pauseContainerID, defaultConfig.ContainerStartTimeout).
Do(func(ctx interface{}, id string, timeout time.Duration) {
// Simulate some startup time
time.Sleep(5 * time.Millisecond)
}).
Return(dockerapi.DockerContainerMetadata{DockerID: "pauseContainerID"}),
dockerClient.EXPECT().InspectContainer(gomock.Any(), gomock.Any(), gomock.Any()).Return(
&types.ContainerJSON{
ContainerJSONBase: &types.ContainerJSONBase{
Expand All @@ -894,9 +912,19 @@ func TestPauseContainerHappyPath(t *testing.T) {
imageManager.EXPECT().AddAllImageStates(gomock.Any()).AnyTimes()
dockerClient.EXPECT().WithVersion(dockerclient.Version_1_35).Times(2).Return(manifestPullClient, nil)
manifestPullClient.EXPECT().
PullImageManifest(gomock.Any(), gomock.Any(), gomock.Any()).Times(2).
PullImageManifest(gomock.Any(), gomock.Any(), gomock.Any()).
Times(2).
Do(func(context.Context, string, *apicontainer.RegistryAuthenticationData) {
assertPauseContainerIsRunning() // Ensure that pause container is already RUNNING
}).
Return(registry.DistributionInspect{}, nil)
dockerClient.EXPECT().PullImage(gomock.Any(), gomock.Any(), nil, gomock.Any()).Return(dockerapi.DockerContainerMetadata{}).Times(2)
dockerClient.EXPECT().
PullImage(gomock.Any(), gomock.Any(), nil, gomock.Any()).
Do(func(context.Context, string, *apicontainer.RegistryAuthenticationData, time.Duration) {
assertPauseContainerIsRunning() // Ensure that pause container is already RUNNING
}).
Return(dockerapi.DockerContainerMetadata{}).
Times(2)
imageManager.EXPECT().RecordContainerReference(gomock.Any()).Return(nil).Times(2)
imageManager.EXPECT().GetImageStateFromImageName(gomock.Any()).Return(nil, false).Times(2)
dockerClient.EXPECT().APIVersion().Return(defaultDockerClientAPIVersion, nil).Times(2)
Expand Down
25 changes: 16 additions & 9 deletions agent/engine/docker_task_engine_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -518,8 +518,13 @@ func TestPauseContainerHappyPath(t *testing.T) {
assert.True(t, ok)
assert.Equal(t, apitask.NetworkPauseContainerName, name)
}).Return(dockerapi.DockerContainerMetadata{DockerID: "pauseContainerID"}),
dockerClient.EXPECT().StartContainer(gomock.Any(), pauseContainerID, defaultConfig.ContainerStartTimeout).Return(
dockerapi.DockerContainerMetadata{DockerID: "pauseContainerID"}),
dockerClient.EXPECT().
StartContainer(gomock.Any(), pauseContainerID, defaultConfig.ContainerStartTimeout).
Do(func(ctx interface{}, id string, timeout time.Duration) {
// Simulate some startup time
time.Sleep(5 * time.Millisecond)
}).
Return(dockerapi.DockerContainerMetadata{DockerID: "pauseContainerID"}),
dockerClient.EXPECT().InspectContainer(gomock.Any(), gomock.Any(), gomock.Any()).Return(
&types.ContainerJSON{
ContainerJSONBase: &types.ContainerJSONBase{
Expand Down Expand Up @@ -567,7 +572,13 @@ func TestPauseContainerHappyPath(t *testing.T) {
assertPauseContainerIsRunning() // Ensure that pause container is already RUNNING
}).
Return(registry.DistributionInspect{}, nil)
dockerClient.EXPECT().PullImage(gomock.Any(), gomock.Any(), nil, gomock.Any()).Return(dockerapi.DockerContainerMetadata{}).Times(2)
dockerClient.EXPECT().
PullImage(gomock.Any(), gomock.Any(), nil, gomock.Any()).
Do(func(context.Context, string, *apicontainer.RegistryAuthenticationData, time.Duration) {
assertPauseContainerIsRunning() // Ensure that pause container is already RUNNING
}).
Return(dockerapi.DockerContainerMetadata{}).
Times(2)
imageManager.EXPECT().RecordContainerReference(gomock.Any()).Return(nil).Times(2)
imageManager.EXPECT().GetImageStateFromImageName(gomock.Any()).Return(nil, false).Times(2)
dockerClient.EXPECT().APIVersion().Return(defaultDockerClientAPIVersion, nil).Times(2)
Expand All @@ -590,12 +601,8 @@ func TestPauseContainerHappyPath(t *testing.T) {
},
}, nil)
cniClient.EXPECT().SetupNS(gomock.Any(), gomock.Any(), gomock.Any()).Return(nsResult, nil)
dockerClient.EXPECT().
StartContainer(gomock.Any(), sleepContainerID2, defaultConfig.ContainerStartTimeout).
Do(func(context.Context, string, *apicontainer.RegistryAuthenticationData) {
assertPauseContainerIsRunning() // Ensure that pause container is already RUNNING
}).
Return(dockerapi.DockerContainerMetadata{DockerID: sleepContainerID2})
dockerClient.EXPECT().StartContainer(gomock.Any(), sleepContainerID2, defaultConfig.ContainerStartTimeout).Return(
dockerapi.DockerContainerMetadata{DockerID: sleepContainerID2})
dockerClient.EXPECT().InspectContainer(gomock.Any(), gomock.Any(), gomock.Any()).Return(
&types.ContainerJSON{
ContainerJSONBase: &types.ContainerJSONBase{
Expand Down

0 comments on commit 3372923

Please sign in to comment.