1
1
package e2e
2
2
3
3
import (
4
- "sync"
5
4
"testing"
6
5
"time"
7
6
18
17
machinePoolsExist bool
19
18
numInitialNodePools int
20
19
numInitialMachineSets int
21
- wg = & sync.WaitGroup {}
22
20
)
23
21
24
22
func TestInstascale (t * testing.T ) {
@@ -65,24 +63,27 @@ func TestInstascale(t *testing.T) {
65
63
}
66
64
defer connection .Close ()
67
65
68
- machinePoolsExist = true
69
66
// check existing cluster resources
70
- numInitialMachinePools , err := MachinePoolsCount (connection )
71
- if err != nil {
72
- test . T (). Errorf ( "Unable to count machine pools - Error : %v" , err )
73
- }
67
+ machinePoolsExist , err := MachinePoolsExist (connection )
68
+ test . Expect ( err ). NotTo ( HaveOccurred ())
69
+ nodePoolsExist , err := NodePoolsExist ( connection )
70
+ test . Expect ( err ). NotTo ( HaveOccurred ())
74
71
75
- if numInitialMachinePools == 0 {
76
- machinePoolsExist = false
77
- numInitialNodePools , err = NodePoolsCount (connection )
72
+ if machinePoolsExist {
73
+ // look for machine pool with aw name - expect not to find it
74
+ foundMachinePool , err := CheckMachinePools (connection , "test-instascale" )
75
+ test .Expect (err ).NotTo (HaveOccurred ())
76
+ test .Expect (foundMachinePool ).To (BeFalse ())
77
+ } else if nodePoolsExist {
78
+ // look for node pool with aw name - expect not to find it
79
+ foundNodePool , err := CheckNodePools (connection , "test-instascale" )
80
+ test .Expect (err ).NotTo (HaveOccurred ())
81
+ test .Expect (foundNodePool ).To (BeFalse ())
82
+ } else {
83
+ // TODO update to foundMachineSet
84
+ numInitialMachineSets , err = MachineSetsCount ()
78
85
if err != nil {
79
- test .T ().Errorf ("Unable to count node pools - Error : %v" , err )
80
- }
81
- if numInitialNodePools == 0 {
82
- numInitialMachineSets , err = MachineSetsCount ()
83
- if err != nil {
84
- test .T ().Errorf ("Unable to count machine sets - Error : %v" , err )
85
- }
86
+ test .T ().Errorf ("Unable to count machine sets - Error : %v" , err )
86
87
}
87
88
}
88
89
@@ -103,13 +104,13 @@ func TestInstascale(t *testing.T) {
103
104
Spec : corev1.PodSpec {
104
105
Containers : []corev1.Container {
105
106
{
106
- Name : "job" ,
107
- Image : GetPyTorchImage (),
107
+ Name : "job" ,
108
+ Image : GetPyTorchImage (),
108
109
Env : []corev1.EnvVar {
109
110
corev1.EnvVar {Name : "PYTHONUSERBASE" , Value : "/test2" },
110
111
},
111
112
Command : []string {"/bin/sh" , "-c" , "pip install -r /test/requirements.txt && torchrun /test/mnist.py" },
112
- Args : []string {"$PYTHONUSERBASE" },
113
+ Args : []string {"$PYTHONUSERBASE" },
113
114
VolumeMounts : []corev1.VolumeMount {
114
115
{
115
116
Name : "test" ,
@@ -184,46 +185,44 @@ func TestInstascale(t *testing.T) {
184
185
},
185
186
},
186
187
},
187
- GenericTemplate : Raw (test , job ),
188
+ GenericTemplate : Raw (test , job ),
189
+ CompletionStatus : "Complete" ,
188
190
},
189
191
},
190
192
},
191
193
},
192
194
}
193
195
194
- _ , err = test .Client ().MCAD ().WorkloadV1beta1 ().AppWrappers (namespace .Name ).Create (test .Ctx (), aw , metav1.CreateOptions {})
196
+ _ , err = test .Client ().MCAD ().WorkloadV1beta1 ().AppWrappers (namespace .Name ).Create (test .Ctx (), aw , metav1.CreateOptions {})
195
197
test .Expect (err ).NotTo (HaveOccurred ())
196
198
test .T ().Logf ("AppWrapper created successfully %s/%s" , aw .Namespace , aw .Name )
197
199
198
200
test .Eventually (AppWrapper (test , namespace , aw .Name ), TestTimeoutShort ).
199
201
Should (WithTransform (AppWrapperState , Equal (mcadv1beta1 .AppWrapperStateActive )))
200
202
201
- // wait for required resources to be created before checking them again
202
- time .Sleep (TestTimeoutShort )
203
- if ! machinePoolsExist {
204
- numNodePools , err := NodePoolsCount (connection )
205
- if err != nil {
206
- test .T ().Errorf ("Unable to count node pools - Error : %v" , err )
207
- }
208
- test .Expect (numNodePools ).To (BeNumerically (">" , numInitialNodePools ))
209
- test .T ().Logf ("number of node pools increased from %d to %d" , numInitialNodePools , numNodePools )
203
+ // time.Sleep is used twice throughout the test, each for 30 seconds. Can look into using sync package waitGroup instead if that makes more sense
204
+ // wait for required resources to scale up before checking them again
205
+ time .Sleep (TestTimeoutThirtySeconds )
210
206
211
- } else if machinePoolsExist {
212
- numMachinePools , err := MachinePoolsCount (connection )
213
- if err != nil {
214
- test .T ().Errorf ("Unable to count machine pools - Error : %v" , err )
215
- }
216
- test .Expect (numMachinePools ).To (BeNumerically (">" , numInitialMachinePools ))
217
- test .T ().Logf ("number of machine pools increased from %d to %d" , numInitialMachinePools , numMachinePools )
207
+ if machinePoolsExist {
208
+ // look for machine pool with aw name - expect to find it
209
+ foundMachinePool , err := CheckMachinePools (connection , "test-instascale" )
210
+ test .Expect (err ).NotTo (HaveOccurred ())
211
+ test .Expect (foundMachinePool ).To (BeTrue ())
212
+ } else if nodePoolsExist {
213
+ // look for node pool with aw name - expect to find it
214
+ foundNodePool , err := CheckNodePools (connection , "test-instascale" )
215
+ test .Expect (err ).NotTo (HaveOccurred ())
216
+ test .Expect (foundNodePool ).To (BeTrue ())
218
217
} else {
219
- numMachineSets , err := MachineSetsCount ()
218
+ // TODO update to foundMachineSet
219
+ numInitialMachineSets , err = MachineSetsCount ()
220
220
if err != nil {
221
221
test .T ().Errorf ("Unable to count machine sets - Error : %v" , err )
222
222
}
223
- test .Expect (numMachineSets ).To (BeNumerically (">" , numInitialMachineSets ))
224
- test .T ().Logf ("number of machine sets increased from %d to %d" , numInitialMachineSets , numMachineSets )
225
223
}
226
-
224
+
225
+ // Assert that the job has completed
227
226
test .T ().Logf ("Waiting for Job %s/%s to complete" , job .Namespace , job .Name )
228
227
test .Eventually (Job (test , job .Namespace , job .Name ), TestTimeoutLong ).Should (
229
228
Or (
@@ -235,30 +234,27 @@ func TestInstascale(t *testing.T) {
235
234
test .Expect (GetJob (test , job .Namespace , job .Name )).
236
235
To (WithTransform (ConditionStatus (batchv1 .JobComplete ), Equal (corev1 .ConditionTrue )))
237
236
238
- // AppWrapper not being updated to complete once job is finished
237
+ test .Eventually (AppWrapper (test , namespace , aw .Name ), TestTimeoutShort ).
238
+ Should (WithTransform (AppWrapperState , Equal (mcadv1beta1 .AppWrapperStateCompleted )))
239
239
240
- time .Sleep (TestTimeoutMedium )
241
- if ! machinePoolsExist {
242
- numNodePoolsFinal , err := NodePoolsCount (connection )
243
- if err != nil {
244
- test .T ().Errorf ("Unable to count node pools - Error : %v" , err )
245
- }
246
- test .Expect (numNodePoolsFinal ).To (BeNumerically ("==" , numInitialNodePools ))
247
- test .T ().Logf ("number of machine pools decreased" )
240
+ // allow time for the resources to scale down before checking them again
241
+ time .Sleep (TestTimeoutThirtySeconds )
248
242
249
- } else if machinePoolsExist {
250
- numMachinePoolsFinal , err := MachinePoolsCount (connection )
251
- if err != nil {
252
- test .T ().Errorf ("Unable to count machine pools - Error : %v" , err )
253
- }
254
- test .Expect (numMachinePoolsFinal ).To (BeNumerically ("==" , numInitialMachinePools ))
255
- test .T ().Logf ("number of machine pools decreased" )
243
+ if machinePoolsExist {
244
+ // look for machine pool with aw name - expect to find it
245
+ foundMachinePool , err := CheckMachinePools (connection , "test-instascale" )
246
+ test .Expect (err ).NotTo (HaveOccurred ())
247
+ test .Expect (foundMachinePool ).To (BeFalse ())
248
+ } else if nodePoolsExist {
249
+ // look for node pool with aw name - expect to find it
250
+ foundNodePool , err := CheckNodePools (connection , "test-instascale" )
251
+ test .Expect (err ).NotTo (HaveOccurred ())
252
+ test .Expect (foundNodePool ).To (BeFalse ())
256
253
} else {
257
- numMachineSetsFinal , err := MachineSetsCount ()
254
+ // TODO update to foundMachineSet
255
+ numInitialMachineSets , err = MachineSetsCount ()
258
256
if err != nil {
259
257
test .T ().Errorf ("Unable to count machine sets - Error : %v" , err )
260
258
}
261
- test .Expect (numMachineSetsFinal ).To (BeNumerically ("==" , numInitialMachineSets ))
262
- test .T ().Logf ("number of machine sets decreased" )
263
259
}
264
260
}
0 commit comments