@@ -64,7 +64,7 @@ func noop() {}
64
64
65
65
func TestWatchRestartsIfTimeoutNotReached (t * testing.T ) {
66
66
// Has to be longer than 5 seconds
67
- timeout := 2 * time .Minute
67
+ timeout := 30 * time .Second
68
68
69
69
// Set up a master
70
70
masterConfig := framework .NewIntegrationTestMasterConfig ()
@@ -204,71 +204,74 @@ func TestWatchRestartsIfTimeoutNotReached(t *testing.T) {
204
204
},
205
205
}
206
206
207
- for _ , tmptc := range tt {
208
- tc := tmptc // we need to copy it for parallel runs
209
- t .Run (tc .name , func (t * testing.T ) {
210
- c , err := kubernetes .NewForConfig (config )
211
- if err != nil {
212
- t .Fatalf ("Failed to create clientset: %v" , err )
213
- }
214
-
215
- secret , err := c .CoreV1 ().Secrets (tc .secret .Namespace ).Create (context .TODO (), tc .secret , metav1.CreateOptions {})
216
- if err != nil {
217
- t .Fatalf ("Failed to create testing secret %s/%s: %v" , tc .secret .Namespace , tc .secret .Name , err )
218
- }
219
-
220
- watcher , err , doneFn := tc .getWatcher (c , secret )
221
- if err != nil {
222
- t .Fatalf ("Failed to create watcher: %v" , err )
223
- }
224
- defer doneFn ()
225
-
226
- var referenceOutput []string
227
- var output []string
228
- stopChan := make (chan struct {})
229
- stoppedChan := make (chan struct {})
230
- go generateEvents (t , c , secret , & referenceOutput , stopChan , stoppedChan )
231
-
232
- // Record current time to be able to asses if the timeout has been reached
233
- startTime := time .Now ()
234
- ctx , cancel := watchtools .ContextWithOptionalTimeout (context .Background (), timeout )
235
- defer cancel ()
236
- _ , err = watchtools .UntilWithoutRetry (ctx , watcher , func (event watch.Event ) (bool , error ) {
237
- s , ok := event .Object .(* corev1.Secret )
238
- if ! ok {
239
- t .Fatalf ("Received an object that is not a Secret: %#v" , event .Object )
207
+ t .Run ("group" , func (t * testing.T ) {
208
+ for _ , tmptc := range tt {
209
+ tc := tmptc // we need to copy it for parallel runs
210
+ t .Run (tc .name , func (t * testing.T ) {
211
+ t .Parallel ()
212
+ c , err := kubernetes .NewForConfig (config )
213
+ if err != nil {
214
+ t .Fatalf ("Failed to create clientset: %v" , err )
240
215
}
241
- output = append (output , s .Annotations ["count" ])
242
- // Watch will never end voluntarily
243
- return false , nil
244
- })
245
- watchDuration := time .Since (startTime )
246
- close (stopChan )
247
- <- stoppedChan
248
-
249
- output = tc .normalizeOutputFunc (output )
250
216
251
- t .Logf ("Watch duration: %v; timeout: %v" , watchDuration , timeout )
217
+ secret , err := c .CoreV1 ().Secrets (tc .secret .Namespace ).Create (context .TODO (), tc .secret , metav1.CreateOptions {})
218
+ if err != nil {
219
+ t .Fatalf ("Failed to create testing secret %s/%s: %v" , tc .secret .Namespace , tc .secret .Name , err )
220
+ }
252
221
253
- if err == nil && ! tc .succeed {
254
- t .Fatalf ("Watch should have timed out but it exited without an error!" )
255
- }
222
+ watcher , err , doneFn := tc .getWatcher (c , secret )
223
+ if err != nil {
224
+ t .Fatalf ("Failed to create watcher: %v" , err )
225
+ }
226
+ defer doneFn ()
227
+
228
+ var referenceOutput []string
229
+ var output []string
230
+ stopChan := make (chan struct {})
231
+ stoppedChan := make (chan struct {})
232
+ go generateEvents (t , c , secret , & referenceOutput , stopChan , stoppedChan )
233
+
234
+ // Record current time to be able to asses if the timeout has been reached
235
+ startTime := time .Now ()
236
+ ctx , cancel := watchtools .ContextWithOptionalTimeout (context .Background (), timeout )
237
+ defer cancel ()
238
+ _ , err = watchtools .UntilWithoutRetry (ctx , watcher , func (event watch.Event ) (bool , error ) {
239
+ s , ok := event .Object .(* corev1.Secret )
240
+ if ! ok {
241
+ t .Fatalf ("Received an object that is not a Secret: %#v" , event .Object )
242
+ }
243
+ output = append (output , s .Annotations ["count" ])
244
+ // Watch will never end voluntarily
245
+ return false , nil
246
+ })
247
+ watchDuration := time .Since (startTime )
248
+ close (stopChan )
249
+ <- stoppedChan
250
+
251
+ output = tc .normalizeOutputFunc (output )
252
+
253
+ t .Logf ("Watch duration: %v; timeout: %v" , watchDuration , timeout )
254
+
255
+ if err == nil && ! tc .succeed {
256
+ t .Fatalf ("Watch should have timed out but it exited without an error!" )
257
+ }
256
258
257
- if err != wait .ErrWaitTimeout && tc .succeed {
258
- t .Fatalf ("Watch exited with error: %v!" , err )
259
- }
259
+ if err != wait .ErrWaitTimeout && tc .succeed {
260
+ t .Fatalf ("Watch exited with error: %v!" , err )
261
+ }
260
262
261
- if watchDuration < timeout && tc .succeed {
262
- t .Fatalf ("Watch should have timed out after %v but it timed out prematurely after %v!" , timeout , watchDuration )
263
- }
263
+ if watchDuration < timeout && tc .succeed {
264
+ t .Fatalf ("Watch should have timed out after %v but it timed out prematurely after %v!" , timeout , watchDuration )
265
+ }
264
266
265
- if watchDuration >= timeout && ! tc .succeed {
266
- t .Fatalf ("Watch should have timed out but it succeeded!" )
267
- }
267
+ if watchDuration >= timeout && ! tc .succeed {
268
+ t .Fatalf ("Watch should have timed out but it succeeded!" )
269
+ }
268
270
269
- if tc .succeed && ! reflect .DeepEqual (referenceOutput , output ) {
270
- t .Fatalf ("Reference and real output differ! We must have lost some events or read some multiple times!\n Ref: %#v\n Real: %#v" , referenceOutput , output )
271
- }
272
- })
273
- }
271
+ if tc .succeed && ! reflect .DeepEqual (referenceOutput , output ) {
272
+ t .Fatalf ("Reference and real output differ! We must have lost some events or read some multiple times!\n Ref: %#v\n Real: %#v" , referenceOutput , output )
273
+ }
274
+ })
275
+ }
276
+ })
274
277
}
0 commit comments