Browse code

extended: update polling for deployment tests

Also fix HasSynced utility to accept a different generation other the one
in the deployment config.

Michail Kargakis authored on 2016/08/30 19:46:09
Showing 4 changed files
... ...
@@ -331,8 +331,10 @@ func IsDeploymentCancelled(deployment *api.ReplicationController) bool {
331 331
 	return strings.EqualFold(value, deployapi.DeploymentCancelledAnnotationValue)
332 332
 }
333 333
 
334
-func HasSynced(dc *deployapi.DeploymentConfig) bool {
335
-	return dc.Status.ObservedGeneration >= dc.Generation
334
+// HasSynced checks if the provided deployment config has been noticed by the deployment
335
+// config controller.
336
+func HasSynced(dc *deployapi.DeploymentConfig, generation int64) bool {
337
+	return dc.Status.ObservedGeneration >= generation
336 338
 }
337 339
 
338 340
 // IsOwnedByConfig checks whether the provided replication controller is part of a
... ...
@@ -216,7 +216,7 @@ var _ = g.Describe("deploymentconfigs", func() {
216 216
 			o.Expect(err).NotTo(o.HaveOccurred())
217 217
 
218 218
 			g.By("ensuring no scale up of the deployment happens")
219
-			wait.Poll(100*time.Millisecond, 10*time.Second, func() (bool, error) {
219
+			wait.PollImmediate(100*time.Millisecond, 10*time.Second, func() (bool, error) {
220 220
 				rc, err := oc.KubeREST().ReplicationControllers(oc.Namespace()).Get("deployment-test-1")
221 221
 				o.Expect(err).NotTo(o.HaveOccurred())
222 222
 				o.Expect(rc.Spec.Replicas).Should(o.BeEquivalentTo(0))
... ...
@@ -396,53 +396,80 @@ var _ = g.Describe("deploymentconfigs", func() {
396 396
 			o.Expect(err).NotTo(o.HaveOccurred())
397 397
 
398 398
 			g.By("verifying that both latestVersion and generation are updated")
399
-			version, err := oc.Run("get").Args(resource, "--output=jsonpath=\"{.status.latestVersion}\"").Output()
400
-			version = strings.Trim(version, "\"")
401
-			o.Expect(err).NotTo(o.HaveOccurred())
402
-			g.By(fmt.Sprintf("checking the latest version for %s: %s", resource, version))
403
-			o.Expect(version).To(o.ContainSubstring("1"))
404
-			generation, err := oc.Run("get").Args(resource, "--output=jsonpath=\"{.metadata.generation}\"").Output()
405
-			o.Expect(err).NotTo(o.HaveOccurred())
406
-			g.By(fmt.Sprintf("checking the generation for %s: %s", resource, generation))
407
-			o.Expect(generation).To(o.ContainSubstring("1"))
399
+			var generation, version string
400
+			err = wait.PollImmediate(500*time.Millisecond, 10*time.Second, func() (bool, error) {
401
+				version, err = oc.Run("get").Args(resource, "--output=jsonpath=\"{.status.latestVersion}\"").Output()
402
+				if err != nil {
403
+					return false, nil
404
+				}
405
+				version = strings.Trim(version, "\"")
406
+				g.By(fmt.Sprintf("checking the latest version for %s: %s", resource, version))
408 407
 
409
-			g.By("verifying the deployment is marked complete")
410
-			err = wait.Poll(100*time.Millisecond, 1*time.Minute, func() (bool, error) {
411
-				rc, err := oc.KubeREST().ReplicationControllers(oc.Namespace()).Get(name + "-" + version)
412
-				o.Expect(err).NotTo(o.HaveOccurred())
413
-				return deployutil.IsTerminatedDeployment(rc), nil
408
+				generation, err = oc.Run("get").Args(resource, "--output=jsonpath=\"{.metadata.generation}\"").Output()
409
+				if err != nil {
410
+					return false, nil
411
+				}
412
+				generation = strings.Trim(generation, "\"")
413
+				g.By(fmt.Sprintf("checking the generation for %s: %s", resource, generation))
414
+
415
+				return strings.Contains(generation, "1") && strings.Contains(version, "1"), nil
414 416
 			})
417
+			if err == wait.ErrWaitTimeout {
418
+				err = fmt.Errorf("expected generation: 1, got: %s, expected latestVersion: 1, got: %s", generation, version)
419
+			}
415 420
 			o.Expect(err).NotTo(o.HaveOccurred())
416 421
 
422
+			g.By("verifying the deployment is marked complete")
423
+			o.Expect(waitForLatestCondition(oc, name, deploymentRunTimeout, deploymentReachedCompletion)).NotTo(o.HaveOccurred())
424
+
417 425
 			g.By("verifying that scaling updates the generation")
418 426
 			_, err = oc.Run("scale").Args(resource, "--replicas=2").Output()
419 427
 			o.Expect(err).NotTo(o.HaveOccurred())
420
-			generation, err = oc.Run("get").Args(resource, "--output=jsonpath=\"{.metadata.generation}\"").Output()
428
+
429
+			err = wait.PollImmediate(500*time.Millisecond, 10*time.Second, func() (bool, error) {
430
+				generation, err = oc.Run("get").Args(resource, "--output=jsonpath=\"{.metadata.generation}\"").Output()
431
+				if err != nil {
432
+					return false, nil
433
+				}
434
+				generation = strings.Trim(generation, "\"")
435
+				g.By(fmt.Sprintf("checking the generation for %s: %s", resource, generation))
436
+
437
+				return strings.Contains(generation, "2"), nil
438
+			})
439
+			if err == wait.ErrWaitTimeout {
440
+				err = fmt.Errorf("expected generation: 2, got: %s", generation)
441
+			}
421 442
 			o.Expect(err).NotTo(o.HaveOccurred())
422
-			g.By(fmt.Sprintf("checking the generation for %s: %s", resource, generation))
423
-			o.Expect(generation).To(o.ContainSubstring("2"))
424 443
 
425 444
 			g.By("deploying a second time [new client]")
426 445
 			_, err = oc.Run("deploy").Args("--latest", name).Output()
427 446
 			o.Expect(err).NotTo(o.HaveOccurred())
428 447
 
429 448
 			g.By("verifying that both latestVersion and generation are updated")
430
-			version, err = oc.Run("get").Args(resource, "--output=jsonpath=\"{.status.latestVersion}\"").Output()
431
-			version = strings.Trim(version, "\"")
432
-			o.Expect(err).NotTo(o.HaveOccurred())
433
-			g.By(fmt.Sprintf("checking the latest version for %s: %s", resource, version))
434
-			o.Expect(version).To(o.ContainSubstring("2"))
435
-			generation, err = oc.Run("get").Args(resource, "--output=jsonpath=\"{.metadata.generation}\"").Output()
449
+			err = wait.PollImmediate(500*time.Millisecond, 10*time.Second, func() (bool, error) {
450
+				version, err = oc.Run("get").Args(resource, "--output=jsonpath=\"{.status.latestVersion}\"").Output()
451
+				if err != nil {
452
+					return false, nil
453
+				}
454
+				version = strings.Trim(version, "\"")
455
+				g.By(fmt.Sprintf("checking the latest version for %s: %s", resource, version))
456
+
457
+				generation, err = oc.Run("get").Args(resource, "--output=jsonpath=\"{.metadata.generation}\"").Output()
458
+				if err != nil {
459
+					return false, nil
460
+				}
461
+				generation = strings.Trim(generation, "\"")
462
+				g.By(fmt.Sprintf("checking the generation for %s: %s", resource, generation))
463
+
464
+				return strings.Contains(generation, "3") && strings.Contains(version, "2"), nil
465
+			})
466
+			if err == wait.ErrWaitTimeout {
467
+				err = fmt.Errorf("expected generation: 3, got: %s, expected latestVersion: 2, got: %s", generation, version)
468
+			}
436 469
 			o.Expect(err).NotTo(o.HaveOccurred())
437
-			g.By(fmt.Sprintf("checking the generation for %s: %s", resource, generation))
438
-			o.Expect(generation).To(o.ContainSubstring("3"))
439 470
 
440 471
 			g.By("verifying that observedGeneration equals generation")
441
-			err = wait.Poll(1*time.Second, 1*time.Minute, func() (bool, error) {
442
-				dc, _, _, err := deploymentInfo(oc, name)
443
-				o.Expect(err).NotTo(o.HaveOccurred())
444
-				return deployutil.HasSynced(dc), nil
445
-			})
472
+			o.Expect(waitForSyncedConfig(oc, name, deploymentRunTimeout)).NotTo(o.HaveOccurred())
446 473
 		})
447 474
 	})
448 475
 
... ...
@@ -613,7 +640,7 @@ var _ = g.Describe("deploymentconfigs", func() {
613 613
 				o.Expect(out).To(o.ContainSubstring("updated"))
614 614
 			}
615 615
 
616
-			o.Expect(waitForLatestCondition(oc, "history-limit", deploymentRunTimeout, checkDeploymentConfigHasSynced)).NotTo(o.HaveOccurred(),
616
+			o.Expect(waitForSyncedConfig(oc, "history-limit", deploymentRunTimeout)).NotTo(o.HaveOccurred(),
617 617
 				"the controller needs to have synced with the updated deployment configuration before checking that the revision history limits are being adhered to")
618 618
 			deploymentConfig, deployments, _, err := deploymentInfo(oc, "history-limit")
619 619
 			o.Expect(err).NotTo(o.HaveOccurred())
... ...
@@ -262,7 +262,7 @@ func deploymentInfo(oc *exutil.CLI, name string) (*deployapi.DeploymentConfig, [
262 262
 type deploymentConditionFunc func(dc *deployapi.DeploymentConfig, rcs []kapi.ReplicationController, pods []kapi.Pod) (bool, error)
263 263
 
264 264
 func waitForLatestCondition(oc *exutil.CLI, name string, timeout time.Duration, fn deploymentConditionFunc) error {
265
-	return wait.Poll(200*time.Millisecond, timeout, func() (bool, error) {
265
+	return wait.PollImmediate(200*time.Millisecond, timeout, func() (bool, error) {
266 266
 		dc, rcs, pods, err := deploymentInfo(oc, name)
267 267
 		if err != nil {
268 268
 			return false, err
... ...
@@ -274,6 +274,20 @@ func waitForLatestCondition(oc *exutil.CLI, name string, timeout time.Duration,
274 274
 	})
275 275
 }
276 276
 
277
+func waitForSyncedConfig(oc *exutil.CLI, name string, timeout time.Duration) error {
278
+	dc, rcs, pods, err := deploymentInfo(oc, name)
279
+	if err != nil {
280
+		return err
281
+	}
282
+	if err := checkDeploymentInvariants(dc, rcs, pods); err != nil {
283
+		return err
284
+	}
285
+	generation := dc.Generation
286
+	return wait.PollImmediate(200*time.Millisecond, timeout, func() (bool, error) {
287
+		return deployutil.HasSynced(dc, generation), nil
288
+	})
289
+}
290
+
277 291
 // createFixture will create the provided fixture and return the resource and the
278 292
 // name separately.
279 293
 // TODO: Probably move to a more general location like test/extended/util/cli.go
... ...
@@ -326,7 +340,3 @@ func failureTrap(oc *exutil.CLI, name string, failed bool) {
326 326
 		}
327 327
 	}
328 328
 }
329
-
330
-func checkDeploymentConfigHasSynced(dc *deployapi.DeploymentConfig, _ []kapi.ReplicationController, _ []kapi.Pod) (bool, error) {
331
-	return deployutil.HasSynced(dc), nil
332
-}
... ...
@@ -47,13 +47,14 @@ func TestDeployScale(t *testing.T) {
47 47
 	if err != nil {
48 48
 		t.Fatalf("Couldn't create DeploymentConfig: %v %#v", err, config)
49 49
 	}
50
+	generation := dc.Generation
50 51
 
51 52
 	condition := func() (bool, error) {
52 53
 		config, err := osClient.DeploymentConfigs(namespace).Get(dc.Name)
53 54
 		if err != nil {
54 55
 			return false, nil
55 56
 		}
56
-		return deployutil.HasSynced(config), nil
57
+		return deployutil.HasSynced(config, generation), nil
57 58
 	}
58 59
 	if err := wait.PollImmediate(500*time.Millisecond, 10*time.Second, condition); err != nil {
59 60
 		t.Fatalf("Deployment config never synced: %v", err)