@@ -1137,9 +1137,11 @@ func TestPauseContainerHappyPath(t *testing.T) {
1137
1137
taskEngine .(* DockerTaskEngine ).cniClient = cniClient
1138
1138
taskEngine .(* DockerTaskEngine ).taskSteadyStatePollInterval = taskSteadyStatePollInterval
1139
1139
eventStream := make (chan dockerapi.DockerContainerChangeEvent )
1140
- sleepTask := testdata .LoadTask ("sleep5" )
1141
- sleepContainer := sleepTask .Containers [0 ]
1142
- sleepContainer .TransitionDependenciesMap = make (map [apicontainerstatus.ContainerStatus ]apicontainer.TransitionDependencySet )
1140
+ sleepTask := testdata .LoadTask ("sleep5TwoContainers" )
1141
+ sleepContainer1 := sleepTask .Containers [0 ]
1142
+ sleepContainer1 .TransitionDependenciesMap = make (map [apicontainerstatus.ContainerStatus ]apicontainer.TransitionDependencySet )
1143
+ sleepContainer2 := sleepTask .Containers [1 ]
1144
+ sleepContainer2 .TransitionDependenciesMap = make (map [apicontainerstatus.ContainerStatus ]apicontainer.TransitionDependencySet )
1143
1145
1144
1146
// Add eni information to the task so the task can add dependency of pause container
1145
1147
sleepTask .AddTaskENI (mockENI )
@@ -1158,6 +1160,8 @@ func TestPauseContainerHappyPath(t *testing.T) {
1158
1160
1159
1161
dockerClient .EXPECT ().ContainerEvents (gomock .Any ()).Return (eventStream , nil )
1160
1162
1163
+ sleepContainerID1 := containerID + "1"
1164
+ sleepContainerID2 := containerID + "2"
1161
1165
pauseContainerID := "pauseContainerID"
1162
1166
// Pause container will be launched first
1163
1167
gomock .InOrder (
@@ -1183,19 +1187,26 @@ func TestPauseContainerHappyPath(t *testing.T) {
1183
1187
1184
1188
// For the other container
1185
1189
imageManager .EXPECT ().AddAllImageStates (gomock .Any ()).AnyTimes ()
1186
- dockerClient .EXPECT ().PullImage (gomock .Any (), gomock .Any (), nil , gomock .Any ()).Return (dockerapi.DockerContainerMetadata {})
1187
- imageManager .EXPECT ().RecordContainerReference (gomock .Any ()).Return (nil )
1188
- imageManager .EXPECT ().GetImageStateFromImageName (gomock .Any ()).Return (nil , false )
1189
- dockerClient .EXPECT ().APIVersion ().Return (defaultDockerClientAPIVersion , nil )
1190
+ dockerClient .EXPECT ().PullImage (gomock .Any (), gomock .Any (), nil , gomock .Any ()).Return (dockerapi.DockerContainerMetadata {}).Times (2 )
1191
+ imageManager .EXPECT ().RecordContainerReference (gomock .Any ()).Return (nil ).Times (2 )
1192
+ imageManager .EXPECT ().GetImageStateFromImageName (gomock .Any ()).Return (nil , false ).Times (2 )
1193
+ dockerClient .EXPECT ().APIVersion ().Return (defaultDockerClientAPIVersion , nil ).Times (2 )
1194
+
1195
+ dockerClient .EXPECT ().CreateContainer (gomock .Any (), gomock .Any (), gomock .Any (),
1196
+ gomock .Any (), gomock .Any ()).Return (dockerapi.DockerContainerMetadata {DockerID : sleepContainerID1 })
1190
1197
dockerClient .EXPECT ().CreateContainer (gomock .Any (), gomock .Any (), gomock .Any (),
1191
- gomock .Any (), gomock .Any ()).Return (dockerapi.DockerContainerMetadata {DockerID : containerID })
1192
- dockerClient .EXPECT ().StartContainer (gomock .Any (), containerID , defaultConfig .ContainerStartTimeout ).Return (
1193
- dockerapi.DockerContainerMetadata {DockerID : containerID })
1198
+ gomock .Any (), gomock .Any ()).Return (dockerapi.DockerContainerMetadata {DockerID : sleepContainerID2 })
1199
+
1200
+ dockerClient .EXPECT ().StartContainer (gomock .Any (), sleepContainerID1 , defaultConfig .ContainerStartTimeout ).Return (
1201
+ dockerapi.DockerContainerMetadata {DockerID : sleepContainerID1 })
1202
+ dockerClient .EXPECT ().StartContainer (gomock .Any (), sleepContainerID2 , defaultConfig .ContainerStartTimeout ).Return (
1203
+ dockerapi.DockerContainerMetadata {DockerID : sleepContainerID2 })
1194
1204
1195
1205
cleanup := make (chan time.Time )
1196
1206
defer close (cleanup )
1197
1207
mockTime .EXPECT ().Now ().Return (time .Now ()).MinTimes (1 )
1198
- dockerClient .EXPECT ().DescribeContainer (gomock .Any (), containerID ).AnyTimes ()
1208
+ dockerClient .EXPECT ().DescribeContainer (gomock .Any (), sleepContainerID1 ).AnyTimes ()
1209
+ dockerClient .EXPECT ().DescribeContainer (gomock .Any (), sleepContainerID2 ).AnyTimes ()
1199
1210
dockerClient .EXPECT ().DescribeContainer (gomock .Any (), pauseContainerID ).AnyTimes ()
1200
1211
1201
1212
err := taskEngine .Init (ctx )
@@ -1208,27 +1219,36 @@ func TestPauseContainerHappyPath(t *testing.T) {
1208
1219
var wg sync.WaitGroup
1209
1220
wg .Add (1 )
1210
1221
mockTime .EXPECT ().After (gomock .Any ()).Return (cleanup ).MinTimes (1 )
1211
- dockerClient .EXPECT ().InspectContainer (gomock .Any (), gomock .Any (), gomock .Any ()).Return (& types.ContainerJSON {
1212
- ContainerJSONBase : & types.ContainerJSONBase {
1213
- ID : pauseContainerID ,
1214
- State : & types.ContainerState {Pid : containerPid },
1215
- },
1216
- }, nil )
1217
- cniClient .EXPECT ().CleanupNS (gomock .Any (), gomock .Any (), gomock .Any ()).Return (nil )
1218
- dockerClient .EXPECT ().StopContainer (gomock .Any (), pauseContainerID , gomock .Any ()).Return (
1219
- dockerapi.DockerContainerMetadata {DockerID : pauseContainerID })
1220
- cniClient .EXPECT ().ReleaseIPResource (gomock .Any (), gomock .Any (), gomock .Any ()).Do (
1221
- func (ctx context.Context , cfg * ecscni.Config , timeout time.Duration ) {
1222
- wg .Done ()
1223
- }).Return (nil )
1224
- dockerClient .EXPECT ().RemoveContainer (gomock .Any (), gomock .Any (), gomock .Any ()).Return (nil ).Times (2 )
1225
- imageManager .EXPECT ().RemoveContainerReferenceFromImageState (gomock .Any ()).Return (nil )
1222
+
1223
+ gomock .InOrder (
1224
+ dockerClient .EXPECT ().StopContainer (gomock .Any (), sleepContainerID2 , gomock .Any ()).Return (
1225
+ dockerapi.DockerContainerMetadata {DockerID : sleepContainerID2 }),
1226
+
1227
+ dockerClient .EXPECT ().InspectContainer (gomock .Any (), pauseContainerID , gomock .Any ()).Return (& types.ContainerJSON {
1228
+ ContainerJSONBase : & types.ContainerJSONBase {
1229
+ ID : pauseContainerID ,
1230
+ State : & types.ContainerState {Pid : containerPid },
1231
+ },
1232
+ }, nil ),
1233
+ cniClient .EXPECT ().CleanupNS (gomock .Any (), gomock .Any (), gomock .Any ()).Return (nil ),
1234
+
1235
+ dockerClient .EXPECT ().StopContainer (gomock .Any (), pauseContainerID , gomock .Any ()).Return (
1236
+ dockerapi.DockerContainerMetadata {DockerID : pauseContainerID }),
1237
+
1238
+ cniClient .EXPECT ().ReleaseIPResource (gomock .Any (), gomock .Any (), gomock .Any ()).Do (
1239
+ func (ctx context.Context , cfg * ecscni.Config , timeout time.Duration ) {
1240
+ wg .Done ()
1241
+ }).Return (nil ),
1242
+ )
1243
+
1244
+ dockerClient .EXPECT ().RemoveContainer (gomock .Any (), gomock .Any (), gomock .Any ()).Return (nil ).Times (3 )
1245
+ imageManager .EXPECT ().RemoveContainerReferenceFromImageState (gomock .Any ()).Return (nil ).Times (2 )
1226
1246
1227
1247
// Simulate a container stop event from docker
1228
1248
eventStream <- dockerapi.DockerContainerChangeEvent {
1229
1249
Status : apicontainerstatus .ContainerStopped ,
1230
1250
DockerContainerMetadata : dockerapi.DockerContainerMetadata {
1231
- DockerID : containerID ,
1251
+ DockerID : sleepContainerID1 ,
1232
1252
ExitCode : aws .Int (exitCode ),
1233
1253
},
1234
1254
}
0 commit comments