@@ -822,6 +822,15 @@ func TestTaskWithSteadyStateResourcesProvisioned(t *testing.T) {
822
822
waitForStopEvents (t , taskEngine .StateChangeEvents (), true , false )
823
823
}
824
824
825
+ // Tests a happy case scenario for an AWSVPC task.
826
+ //
827
+ // This test also verifies that
828
+ // any DockerClient calls that interact with an image repository (PullContainerManifest
829
+ // and PullContainer, currently) happen after the pause container has reached
830
+ // ContainerResourcesProvisioned state.
831
+ //
832
+ // If you are updating this test then make sure that you call assertPauseContainerIsRunning()
833
+ // in any dockerClient expected calls that are supposed to interact with an image repository.
825
834
func TestPauseContainerHappyPath (t * testing.T ) {
826
835
ctx , cancel := context .WithCancel (context .TODO ())
827
836
defer cancel ()
@@ -857,6 +866,19 @@ func TestPauseContainerHappyPath(t *testing.T) {
857
866
dockerClient .EXPECT ().ContainerEvents (gomock .Any ()).Return (eventStream , nil )
858
867
serviceConnectManager .EXPECT ().GetAppnetContainerTarballDir ().AnyTimes ()
859
868
869
+ // A function to assert that the network pause container in the task is in
870
+ // ContainerResourcesProvisioned state. This will be used by dockerClient mock later.
871
+ assertPauseContainerIsRunning := func () {
872
+ assert .Len (t , sleepTask .Containers , 3 , "expected pause container to be populated" )
873
+ pauseContainer := sleepTask .Containers [2 ]
874
+ assert .Equal (t , apitask .NetworkPauseContainerName , pauseContainer .Name )
875
+ assert .Equal (t , apicontainer .ContainerCNIPause , pauseContainer .Type )
876
+ assert .Equal (t ,
877
+ apicontainerstatus .ContainerResourcesProvisioned ,
878
+ pauseContainer .GetKnownStatus (),
879
+ "expected pause container to be running before image repository is called" )
880
+ }
881
+
860
882
sleepContainerID1 := containerID + "1"
861
883
sleepContainerID2 := containerID + "2"
862
884
pauseContainerID := "pauseContainerID"
@@ -870,8 +892,13 @@ func TestPauseContainerHappyPath(t *testing.T) {
870
892
assert .True (t , ok )
871
893
assert .Equal (t , apitask .NetworkPauseContainerName , name )
872
894
}).Return (dockerapi.DockerContainerMetadata {DockerID : "pauseContainerID" }),
873
- dockerClient .EXPECT ().StartContainer (gomock .Any (), pauseContainerID , defaultConfig .ContainerStartTimeout ).Return (
874
- dockerapi.DockerContainerMetadata {DockerID : "pauseContainerID" }),
895
+ dockerClient .EXPECT ().
896
+ StartContainer (gomock .Any (), pauseContainerID , defaultConfig .ContainerStartTimeout ).
897
+ Do (func (ctx interface {}, id string , timeout time.Duration ) {
898
+ // Simulate some startup time
899
+ time .Sleep (5 * time .Millisecond )
900
+ }).
901
+ Return (dockerapi.DockerContainerMetadata {DockerID : "pauseContainerID" }),
875
902
dockerClient .EXPECT ().InspectContainer (gomock .Any (), gomock .Any (), gomock .Any ()).Return (
876
903
& types.ContainerJSON {
877
904
ContainerJSONBase : & types.ContainerJSONBase {
@@ -892,9 +919,19 @@ func TestPauseContainerHappyPath(t *testing.T) {
892
919
imageManager .EXPECT ().AddAllImageStates (gomock .Any ()).AnyTimes ()
893
920
dockerClient .EXPECT ().WithVersion (dockerclient .Version_1_35 ).Times (2 ).Return (manifestPullClient , nil )
894
921
manifestPullClient .EXPECT ().
895
- PullImageManifest (gomock .Any (), gomock .Any (), gomock .Any ()).Times (2 ).
922
+ PullImageManifest (gomock .Any (), gomock .Any (), gomock .Any ()).
923
+ Times (2 ).
924
+ Do (func (context.Context , string , * apicontainer.RegistryAuthenticationData ) {
925
+ assertPauseContainerIsRunning () // Ensure that pause container is already RUNNING
926
+ }).
896
927
Return (registry.DistributionInspect {}, nil )
897
- dockerClient .EXPECT ().PullImage (gomock .Any (), gomock .Any (), nil , gomock .Any ()).Return (dockerapi.DockerContainerMetadata {}).Times (2 )
928
+ dockerClient .EXPECT ().
929
+ PullImage (gomock .Any (), gomock .Any (), nil , gomock .Any ()).
930
+ Do (func (context.Context , string , * apicontainer.RegistryAuthenticationData , time.Duration ) {
931
+ assertPauseContainerIsRunning () // Ensure that pause container is already RUNNING
932
+ }).
933
+ Return (dockerapi.DockerContainerMetadata {}).
934
+ Times (2 )
898
935
imageManager .EXPECT ().RecordContainerReference (gomock .Any ()).Return (nil ).Times (2 )
899
936
imageManager .EXPECT ().GetImageStateFromImageName (gomock .Any ()).Return (nil , false ).Times (2 )
900
937
dockerClient .EXPECT ().APIVersion ().Return (defaultDockerClientAPIVersion , nil ).Times (2 )
0 commit comments