From 87d71b5fcdc63e5636414fd3de520917ad352947 Mon Sep 17 00:00:00 2001 From: Greg Weresch Date: Wed, 14 Aug 2024 13:55:30 -0400 Subject: [PATCH] [v8] Max in flight status tests (#3100) * Add copy-source tests to verify max-in-flight output * Add rollback tests to verify max-in-flight output * Add restage tests to verify max-in-flight output * Add restart tests to verify max-in-flight output * Add push tests to verify max-in-flight output --- .../v7/isolated/copy_source_command_test.go | 27 ++++++- .../v7/isolated/restage_command_test.go | 23 +++++- .../v7/isolated/restart_command_test.go | 34 +++++++- .../v7/isolated/rollback_command_test.go | 26 ++++++- integration/v7/push/canary_push_test.go | 77 ++++++++++++++----- 5 files changed, 157 insertions(+), 30 deletions(-) diff --git a/integration/v7/isolated/copy_source_command_test.go b/integration/v7/isolated/copy_source_command_test.go index bd8829140ca..e0495b4f050 100644 --- a/integration/v7/isolated/copy_source_command_test.go +++ b/integration/v7/isolated/copy_source_command_test.go @@ -374,7 +374,7 @@ var _ = Describe("copy-source command", func() { }) helpers.WithBananaPantsApp(func(appDir string) { - Eventually(helpers.CF("push", targetAppName, "--no-start", "-p", appDir, "-b", "staticfile_buildpack")).Should(Exit(0)) + Eventually(helpers.CF("push", targetAppName, "-p", appDir, "-b", "staticfile_buildpack")).Should(Exit(0)) }) }) @@ -388,9 +388,32 @@ var _ = Describe("copy-source command", func() { Eventually(session).Should(Say("Copying source from app %s to target app %s in org %s / space %s as %s...", sourceAppName, targetAppName, orgName, spaceName, username)) Eventually(session).Should(Say("Staging app %s in org %s / space %s as %s...", targetAppName, orgName, spaceName, username)) Eventually(session).Should(Say("Waiting for app to deploy...")) + Eventually(session).Should(Say("Canary deployment currently PAUSED")) + Eventually(session).ShouldNot(Say("max-in-flight")) + Eventually(session).Should(Say("Please run `cf continue-deployment %s` to promote the canary deployment, or `cf cancel-deployment %s` to rollback to the previous version.", targetAppName, targetAppName)) Eventually(session).Should(Exit(0)) - Eventually(helpers.CF("start", targetAppName)).Should(Exit(0)) + Eventually(helpers.CF("continue-deployment", targetAppName)).Should(Exit(0)) + resp, err := http.Get(fmt.Sprintf("http://%s.%s", targetAppName, helpers.DefaultSharedDomain())) + Expect(err).ToNot(HaveOccurred()) + defer resp.Body.Close() + body, err := io.ReadAll(resp.Body) + Expect(err).ToNot(HaveOccurred()) + Expect(string(body)).To(MatchRegexp("hello world")) + }) + + It("displays max-in-flight when it is not the default value", func() { + username, _ := helpers.GetCredentials() + session := helpers.CF("copy-source", sourceAppName, targetAppName, "--strategy", "canary", "--max-in-flight", "2") + Eventually(session).Should(Say("Copying source from app %s to target app %s in org %s / space %s as %s...", sourceAppName, targetAppName, orgName, spaceName, username)) + Eventually(session).Should(Say("Staging app %s in org %s / space %s as %s...", targetAppName, orgName, spaceName, username)) + Eventually(session).Should(Say("Waiting for app to deploy...")) + Eventually(session).Should(Say("Canary deployment currently PAUSED")) + Eventually(session).Should(Say("max-in-flight: 2")) + Eventually(session).Should(Say("Please run `cf continue-deployment %s` to promote the canary deployment, or `cf cancel-deployment %s` to rollback to the previous version.", targetAppName, targetAppName)) + Eventually(session).Should(Exit(0)) + + Eventually(helpers.CF("continue-deployment", targetAppName)).Should(Exit(0)) resp, err := http.Get(fmt.Sprintf("http://%s.%s", targetAppName, helpers.DefaultSharedDomain())) Expect(err).ToNot(HaveOccurred()) defer resp.Body.Close() diff --git a/integration/v7/isolated/restage_command_test.go b/integration/v7/isolated/restage_command_test.go index 97f2317d6a1..d2d84c52019 100644 --- a/integration/v7/isolated/restage_command_test.go +++ b/integration/v7/isolated/restage_command_test.go @@ -231,15 +231,32 @@ applications: }) }) - When("strategy canary is given", func() { - It("restages successfully", func() { + When("strategy canary is given without the max-in-flight flag", func() { + It("restages successfully without noting max-in-flight", func() { userName, _ := helpers.GetCredentials() session := helpers.CF("restage", appName, "--strategy", "canary") Consistently(session.Err).ShouldNot(Say(`This action will cause app downtime\.`)) Eventually(session).Should(Say(`Restaging app %s in org %s / space %s as %s\.\.\.`, appName, orgName, spaceName, userName)) Eventually(session).Should(Say(`Creating deployment for app %s\.\.\.`, appName)) Eventually(session).Should(Say(`Waiting for app to deploy\.\.\.`)) - Eventually(session).Should(Say("Canary deployment currently PAUSED.")) + Eventually(session).Should(Say("Canary deployment currently PAUSED")) + Eventually(session).ShouldNot(Say("max-in-flight")) + Eventually(session).Should(Say("Please run `cf continue-deployment %s` to promote the canary deployment, or `cf cancel-deployment %s` to rollback to the previous version.", appName, appName)) + Eventually(session).Should(Exit(0)) + }) + }) + + When("strategy canary is given with a non-default max-in-flight value", func() { + It("restages successfully and notes the max-in-flight value", func() { + userName, _ := helpers.GetCredentials() + session := helpers.CF("restage", appName, "--strategy", "canary", "--max-in-flight", "2") + Consistently(session.Err).ShouldNot(Say(`This action will cause app downtime\.`)) + Eventually(session).Should(Say(`Restaging app %s in org %s / space %s as %s\.\.\.`, appName, orgName, spaceName, userName)) + Eventually(session).Should(Say(`Creating deployment for app %s\.\.\.`, appName)) + Eventually(session).Should(Say(`Waiting for app to deploy\.\.\.`)) + Eventually(session).Should(Say("Canary deployment currently PAUSED")) + Eventually(session).Should(Say("max-in-flight: 2")) + Eventually(session).Should(Say("Please run `cf continue-deployment %s` to promote the canary deployment, or `cf cancel-deployment %s` to rollback to the previous version.", appName, appName)) Eventually(session).Should(Exit(0)) }) }) diff --git a/integration/v7/isolated/restart_command_test.go b/integration/v7/isolated/restart_command_test.go index 82ebf8239e9..64cad204ad4 100644 --- a/integration/v7/isolated/restart_command_test.go +++ b/integration/v7/isolated/restart_command_test.go @@ -117,13 +117,13 @@ var _ = Describe("restart command", func() { }) }) - When("strategy canary is given", func() { + When("strategy canary is given without the max-in-flight flag", func() { BeforeEach(func() { helpers.WithHelloWorldApp(func(appDir string) { Eventually(helpers.CustomCF(helpers.CFEnv{WorkingDirectory: appDir}, "push", appName)).Should(Exit(0)) }) }) - It("creates a deploy", func() { + It("creates a deploy without noting max-in-flight", func() { session := helpers.CF("restart", appName, "--strategy=canary") Eventually(session).Should(Say(`Restarting app %s in org %s / space %s as %s\.\.\.`, appName, orgName, spaceName, userName)) Eventually(session).Should(Say(`Creating deployment for app %s\.\.\.`, appName)) @@ -136,6 +136,36 @@ var _ = Describe("restart command", func() { Eventually(session).Should(Say(`memory usage:\s+\d+(M|G)`)) Eventually(session).Should(Say(instanceStatsTitles)) Eventually(session).Should(Say(instanceStatsValues)) + Eventually(session).Should(Say("Canary deployment currently PAUSED")) + Eventually(session).ShouldNot(Say("max-in-flight")) + Eventually(session).Should(Say("Please run `cf continue-deployment %s` to promote the canary deployment, or `cf cancel-deployment %s` to rollback to the previous version.", appName, appName)) + Eventually(session).Should(Exit(0)) + }) + }) + + When("strategy canary is given with a non-default max-in-flight value", func() { + BeforeEach(func() { + helpers.WithHelloWorldApp(func(appDir string) { + Eventually(helpers.CustomCF(helpers.CFEnv{WorkingDirectory: appDir}, "push", appName)).Should(Exit(0)) + }) + }) + It("creates a deploy and notes the max-in-flight value", func() { + session := helpers.CF("restart", appName, "--strategy=canary", "--max-in-flight", "3") + Eventually(session).Should(Say(`Restarting app %s in org %s / space %s as %s\.\.\.`, appName, orgName, spaceName, userName)) + Eventually(session).Should(Say(`Creating deployment for app %s\.\.\.`, appName)) + Eventually(session).Should(Say(`Waiting for app to deploy\.\.\.`)) + Eventually(session).Should(Say(`name:\s+%s`, appName)) + Eventually(session).Should(Say(`requested state:\s+started`)) + Eventually(session).Should(Say(`routes:\s+%s.%s`, appName, helpers.DefaultSharedDomain())) + Eventually(session).Should(Say(`type:\s+web`)) + Eventually(session).Should(Say(`instances:\s+1/1`)) + Eventually(session).Should(Say(`memory usage:\s+\d+(M|G)`)) + Eventually(session).Should(Say(instanceStatsTitles)) + Eventually(session).Should(Say(instanceStatsValues)) + Eventually(session).Should(Say("Canary deployment currently PAUSED")) + Eventually(session).Should(Say("max-in-flight: 3")) + Eventually(session).Should(Say("Please run `cf continue-deployment %s` to promote the canary deployment, or `cf cancel-deployment %s` to rollback to the previous version.", appName, appName)) + Eventually(session).Should(Exit(0)) }) }) diff --git a/integration/v7/isolated/rollback_command_test.go b/integration/v7/isolated/rollback_command_test.go index 3e8bf1eb0cd..7a2875a9348 100644 --- a/integration/v7/isolated/rollback_command_test.go +++ b/integration/v7/isolated/rollback_command_test.go @@ -151,18 +151,40 @@ applications: Expect(session).To(Say(`3\(deployed\)\s+New droplet deployed.`)) }) - When("the strategy flag is provided", func() { + When("the strategy flag is provided without the max-in-flight flag", func() { BeforeEach(func() { _, err := buffer.Write([]byte("y\n")) Expect(err).ToNot(HaveOccurred()) }) - It("uses the given strategy to rollback", func() { + It("uses the given strategy to rollback without noting max-in-flight", func() { session := helpers.CFWithStdin(buffer, "rollback", appName, "--version", "1", "--strategy", "canary") Eventually(session).Should(Exit(0)) Expect(session).To(HaveRollbackPrompt()) Expect(session).To(HaveRollbackOutput(appName, orgName, spaceName, userName)) + Expect(session).To(Say("Canary deployment currently PAUSED")) + Expect(session).NotTo(Say("max-in-flight")) + Expect(session).To(Say("Please run `cf continue-deployment %s` to promote the canary deployment, or `cf cancel-deployment %s` to rollback to the previous version.", appName, appName)) + Expect(session).To(Say("OK")) + }) + }) + + When("the strategy flag is provided with a non-default max-in-flight value", func() { + BeforeEach(func() { + _, err := buffer.Write([]byte("y\n")) + Expect(err).ToNot(HaveOccurred()) + }) + + It("uses the given strategy to rollback and notes the max-in-flight value", func() { + session := helpers.CFWithStdin(buffer, "rollback", appName, "--version", "1", "--strategy", "canary", "--max-in-flight", "2") + Eventually(session).Should(Exit(0)) + + Expect(session).To(HaveRollbackPrompt()) + Expect(session).To(HaveRollbackOutput(appName, orgName, spaceName, userName)) + Expect(session).To(Say("Canary deployment currently PAUSED")) + Expect(session).To(Say("max-in-flight: 2")) + Expect(session).To(Say("Please run `cf continue-deployment %s` to promote the canary deployment, or `cf cancel-deployment %s` to rollback to the previous version.", appName, appName)) Expect(session).To(Say("OK")) }) }) diff --git a/integration/v7/push/canary_push_test.go b/integration/v7/push/canary_push_test.go index 4dd9a89adb7..4fcbed184ca 100644 --- a/integration/v7/push/canary_push_test.go +++ b/integration/v7/push/canary_push_test.go @@ -30,28 +30,63 @@ var _ = Describe("push with --strategy canary", func() { }) }) - It("pushes the app and creates a new deployment", func() { - helpers.WithHelloWorldApp(func(appDir string) { - session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: appDir}, - PushCommandName, appName, "--strategy", "canary", - ) + When("the max-in-flight flag is not given", func() { + It("pushes the app and creates a new deployment without noting max-in-flight", func() { + helpers.WithHelloWorldApp(func(appDir string) { + session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: appDir}, + PushCommandName, appName, "--strategy", "canary", + ) - Eventually(session).Should(Exit(0)) - Expect(session).To(Say(`Pushing app %s to org %s / space %s as %s\.\.\.`, appName, organization, space, userName)) - Expect(session).To(Say(`Packaging files to upload\.\.\.`)) - Expect(session).To(Say(`Uploading files\.\.\.`)) - Expect(session).To(Say(`100.00%`)) - Expect(session).To(Say(`Waiting for API to complete processing files\.\.\.`)) - Expect(session).To(Say(`Staging app and tracing logs\.\.\.`)) - Expect(session).To(Say(`Starting deployment for app %s\.\.\.`, appName)) - Expect(session).To(Say(`Waiting for app to deploy\.\.\.`)) - Expect(session).To(Say(`name:\s+%s`, appName)) - Expect(session).To(Say(`requested state:\s+started`)) - Expect(session).To(Say(`routes:\s+%s.%s`, appName, helpers.DefaultSharedDomain())) - Expect(session).To(Say(`type:\s+web`)) - Expect(session).To(Say(`start command:\s+%s`, helpers.StaticfileBuildpackStartCommand)) - Expect(session).To(Say(`#0\s+running`)) - Expect(session).To(Say(`Canary deployment currently PAUSED.`)) + Eventually(session).Should(Exit(0)) + Expect(session).To(Say(`Pushing app %s to org %s / space %s as %s\.\.\.`, appName, organization, space, userName)) + Expect(session).To(Say(`Packaging files to upload\.\.\.`)) + Expect(session).To(Say(`Uploading files\.\.\.`)) + Expect(session).To(Say(`100.00%`)) + Expect(session).To(Say(`Waiting for API to complete processing files\.\.\.`)) + Expect(session).To(Say(`Staging app and tracing logs\.\.\.`)) + Expect(session).To(Say(`Starting deployment for app %s\.\.\.`, appName)) + Expect(session).To(Say(`Waiting for app to deploy\.\.\.`)) + Expect(session).To(Say(`name:\s+%s`, appName)) + Expect(session).To(Say(`requested state:\s+started`)) + Expect(session).To(Say(`routes:\s+%s.%s`, appName, helpers.DefaultSharedDomain())) + Expect(session).To(Say(`type:\s+web`)) + Expect(session).To(Say(`start command:\s+%s`, helpers.StaticfileBuildpackStartCommand)) + Expect(session).To(Say(`#0\s+running`)) + Expect(session).To(Say(`Canary deployment currently PAUSED`)) + Expect(session).ToNot(Say("max-in-flight")) + Expect(session).To(Say("Please run `cf continue-deployment %s` to promote the canary deployment, or `cf cancel-deployment %s` to rollback to the previous version.", appName, appName)) + Expect(session).To(Exit(0)) + }) + }) + }) + + When("the max-in-flight flag is given with a non-default value", func() { + It("pushes the app and creates a new deployment and notes the max-in-flight value", func() { + helpers.WithHelloWorldApp(func(appDir string) { + session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: appDir}, + PushCommandName, appName, "--strategy", "canary", "--max-in-flight", "2", + ) + + Eventually(session).Should(Exit(0)) + Expect(session).To(Say(`Pushing app %s to org %s / space %s as %s\.\.\.`, appName, organization, space, userName)) + Expect(session).To(Say(`Packaging files to upload\.\.\.`)) + Expect(session).To(Say(`Uploading files\.\.\.`)) + Expect(session).To(Say(`100.00%`)) + Expect(session).To(Say(`Waiting for API to complete processing files\.\.\.`)) + Expect(session).To(Say(`Staging app and tracing logs\.\.\.`)) + Expect(session).To(Say(`Starting deployment for app %s\.\.\.`, appName)) + Expect(session).To(Say(`Waiting for app to deploy\.\.\.`)) + Expect(session).To(Say(`name:\s+%s`, appName)) + Expect(session).To(Say(`requested state:\s+started`)) + Expect(session).To(Say(`routes:\s+%s.%s`, appName, helpers.DefaultSharedDomain())) + Expect(session).To(Say(`type:\s+web`)) + Expect(session).To(Say(`start command:\s+%s`, helpers.StaticfileBuildpackStartCommand)) + Expect(session).To(Say(`#0\s+running`)) + Expect(session).To(Say(`Canary deployment currently PAUSED`)) + Expect(session).To(Say("max-in-flight: 2")) + Expect(session).To(Say("Please run `cf continue-deployment %s` to promote the canary deployment, or `cf cancel-deployment %s` to rollback to the previous version.", appName, appName)) + Expect(session).To(Exit(0)) + }) }) }) })