1
1
package e2e
2
2
3
3
import (
4
- "sync"
5
4
"testing"
6
5
"time"
7
6
@@ -14,13 +13,6 @@ import (
14
13
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
15
14
)
16
15
17
- var (
18
- machinePoolsExist bool
19
- numInitialNodePools int
20
- numInitialMachineSets int
21
- wg = & sync.WaitGroup {}
22
- )
23
-
24
16
func TestInstascale (t * testing.T ) {
25
17
26
18
test := With (t )
@@ -65,25 +57,25 @@ func TestInstascale(t *testing.T) {
65
57
}
66
58
defer connection .Close ()
67
59
68
- machinePoolsExist = true
69
60
// 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
- }
61
+ machinePoolsExist , err := MachinePoolsExist (connection )
62
+ test . Expect ( err ). NotTo ( HaveOccurred ())
63
+ nodePoolsExist , err := NodePoolsExist ( connection )
64
+ test . Expect ( err ). NotTo ( HaveOccurred ())
74
65
75
- if numInitialMachinePools == 0 {
76
- machinePoolsExist = false
77
- numInitialNodePools , err = NodePoolsCount (connection )
78
- 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
- }
66
+ if machinePoolsExist {
67
+ // look for machine pool with aw name - expect not to find it
68
+ foundMachinePool , err := CheckMachinePools (connection , "test-instascale" )
69
+ test .Expect (err ).NotTo (HaveOccurred ())
70
+ test .Expect (foundMachinePool ).To (BeFalse ())
71
+ } else if nodePoolsExist {
72
+ // look for node pool with aw name - expect not to find it
73
+ foundNodePool , err := CheckNodePools (connection , "test-instascale" )
74
+ test .Expect (err ).NotTo (HaveOccurred ())
75
+ test .Expect (foundNodePool ).To (BeFalse ())
76
+ } else {
77
+ // TODO update to foundMachineSet
78
+
87
79
}
88
80
89
81
// Batch Job
@@ -103,13 +95,13 @@ func TestInstascale(t *testing.T) {
103
95
Spec : corev1.PodSpec {
104
96
Containers : []corev1.Container {
105
97
{
106
- Name : "job" ,
107
- Image : GetPyTorchImage (),
98
+ Name : "job" ,
99
+ Image : GetPyTorchImage (),
108
100
Env : []corev1.EnvVar {
109
101
corev1.EnvVar {Name : "PYTHONUSERBASE" , Value : "/test2" },
110
102
},
111
103
Command : []string {"/bin/sh" , "-c" , "pip install -r /test/requirements.txt && torchrun /test/mnist.py" },
112
- Args : []string {"$PYTHONUSERBASE" },
104
+ Args : []string {"$PYTHONUSERBASE" },
113
105
VolumeMounts : []corev1.VolumeMount {
114
106
{
115
107
Name : "test" ,
@@ -184,46 +176,41 @@ func TestInstascale(t *testing.T) {
184
176
},
185
177
},
186
178
},
187
- GenericTemplate : Raw (test , job ),
179
+ GenericTemplate : Raw (test , job ),
180
+ CompletionStatus : "Complete" ,
188
181
},
189
182
},
190
183
},
191
184
},
192
185
}
193
186
194
- _ , err = test .Client ().MCAD ().WorkloadV1beta1 ().AppWrappers (namespace .Name ).Create (test .Ctx (), aw , metav1.CreateOptions {})
187
+ _ , err = test .Client ().MCAD ().WorkloadV1beta1 ().AppWrappers (namespace .Name ).Create (test .Ctx (), aw , metav1.CreateOptions {})
195
188
test .Expect (err ).NotTo (HaveOccurred ())
196
189
test .T ().Logf ("AppWrapper created successfully %s/%s" , aw .Namespace , aw .Name )
197
190
198
191
test .Eventually (AppWrapper (test , namespace , aw .Name ), TestTimeoutShort ).
199
192
Should (WithTransform (AppWrapperState , Equal (mcadv1beta1 .AppWrapperStateActive )))
200
193
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 )
210
-
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 )
194
+ // 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
195
+ // wait for required resources to scale up before checking them again
196
+ time .Sleep (TestTimeoutThirtySeconds )
197
+
198
+ if machinePoolsExist {
199
+ // look for machine pool with aw name - expect to find it
200
+ foundMachinePool , err := CheckMachinePools (connection , "test-instascale" )
201
+ test .Expect (err ).NotTo (HaveOccurred ())
202
+ test .Expect (foundMachinePool ).To (BeTrue ())
203
+ } else if nodePoolsExist {
204
+ // look for node pool with aw name - expect to find it
205
+ foundNodePool , err := CheckNodePools (connection , "test-instascale" )
206
+ test .Expect (err ).NotTo (HaveOccurred ())
207
+ test .Expect (foundNodePool ).To (BeTrue ())
218
208
} else {
219
- numMachineSets , err := MachineSetsCount ()
220
- if err != nil {
221
- test .T ().Errorf ("Unable to count machine sets - Error : %v" , err )
222
- }
223
- test .Expect (numMachineSets ).To (BeNumerically (">" , numInitialMachineSets ))
224
- test .T ().Logf ("number of machine sets increased from %d to %d" , numInitialMachineSets , numMachineSets )
209
+ // TODO update to foundMachineSet
210
+
225
211
}
226
-
212
+
213
+ // Assert that the job has completed
227
214
test .T ().Logf ("Waiting for Job %s/%s to complete" , job .Namespace , job .Name )
228
215
test .Eventually (Job (test , job .Namespace , job .Name ), TestTimeoutLong ).Should (
229
216
Or (
@@ -235,30 +222,24 @@ func TestInstascale(t *testing.T) {
235
222
test .Expect (GetJob (test , job .Namespace , job .Name )).
236
223
To (WithTransform (ConditionStatus (batchv1 .JobComplete ), Equal (corev1 .ConditionTrue )))
237
224
238
- // AppWrapper not being updated to complete once job is finished
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" )
248
-
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" )
225
+ test .Eventually (AppWrapper (test , namespace , aw .Name ), TestTimeoutShort ).
226
+ Should (WithTransform (AppWrapperState , Equal (mcadv1beta1 .AppWrapperStateCompleted )))
227
+
228
+ // allow time for the resources to scale down before checking them again
229
+ time .Sleep (TestTimeoutThirtySeconds )
230
+
231
+ if machinePoolsExist {
232
+ // look for machine pool with aw name - expect to find it
233
+ foundMachinePool , err := CheckMachinePools (connection , "test-instascale" )
234
+ test .Expect (err ).NotTo (HaveOccurred ())
235
+ test .Expect (foundMachinePool ).To (BeFalse ())
236
+ } else if nodePoolsExist {
237
+ // look for node pool with aw name - expect to find it
238
+ foundNodePool , err := CheckNodePools (connection , "test-instascale" )
239
+ test .Expect (err ).NotTo (HaveOccurred ())
240
+ test .Expect (foundNodePool ).To (BeFalse ())
256
241
} else {
257
- numMachineSetsFinal , err := MachineSetsCount ()
258
- if err != nil {
259
- test .T ().Errorf ("Unable to count machine sets - Error : %v" , err )
260
- }
261
- test .Expect (numMachineSetsFinal ).To (BeNumerically ("==" , numInitialMachineSets ))
262
- test .T ().Logf ("number of machine sets decreased" )
242
+ // TODO update to foundMachineSet
243
+
263
244
}
264
245
}
0 commit comments