diff --git a/orca-queue/src/main/kotlin/com/netflix/spinnaker/orca/q/handler/StartStageHandler.kt b/orca-queue/src/main/kotlin/com/netflix/spinnaker/orca/q/handler/StartStageHandler.kt index 06e9af2bb2..3a18214ff1 100644 --- a/orca-queue/src/main/kotlin/com/netflix/spinnaker/orca/q/handler/StartStageHandler.kt +++ b/orca-queue/src/main/kotlin/com/netflix/spinnaker/orca/q/handler/StartStageHandler.kt @@ -95,7 +95,6 @@ class StartStageHandler( try { // Set the startTime in case we throw an exception. stage.startTime = clock.millis() - repository.storeStage(stage) stage.plan() stage.status = RUNNING repository.storeStage(stage) diff --git a/orca-queue/src/test/kotlin/com/netflix/spinnaker/orca/q/handler/StartStageHandlerTest.kt b/orca-queue/src/test/kotlin/com/netflix/spinnaker/orca/q/handler/StartStageHandlerTest.kt index ae5ded7972..adb4886e2c 100644 --- a/orca-queue/src/test/kotlin/com/netflix/spinnaker/orca/q/handler/StartStageHandlerTest.kt +++ b/orca-queue/src/test/kotlin/com/netflix/spinnaker/orca/q/handler/StartStageHandlerTest.kt @@ -162,7 +162,7 @@ object StartStageHandlerTest : SubjectSpek({ } it("updates the stage status") { - verify(repository, times(2)).storeStage( + verify(repository).storeStage( check { assertThat(it.status).isEqualTo(RUNNING) assertThat(it.startTime).isEqualTo(clock.millis()) @@ -171,7 +171,7 @@ object StartStageHandlerTest : SubjectSpek({ } it("attaches tasks to the stage") { - verify(repository, times(2)).storeStage( + verify(repository).storeStage( check { assertThat(it.tasks.size).isEqualTo(1) it.tasks.first().apply { @@ -222,7 +222,7 @@ object StartStageHandlerTest : SubjectSpek({ } it("updates the stage status") { - verify(repository, times(2)).storeStage( + verify(repository).storeStage( check { assertThat(it.status).isEqualTo(RUNNING) assertThat(it.startTime).isEqualTo(clock.millis()) @@ -267,7 +267,7 @@ object StartStageHandlerTest : SubjectSpek({ } it("updates the stage status") { - verify(repository, times(2)).storeStage( + verify(repository).storeStage( check { assertThat(it.status).isEqualTo(RUNNING) assertThat(it.startTime).isEqualTo(clock.millis()) @@ -312,7 +312,7 @@ object StartStageHandlerTest : SubjectSpek({ afterGroup(::resetMocks) it("attaches tasks to the stage") { - verify(repository, times(2)).storeStage( + verify(repository).storeStage( check { assertThat(it.tasks.size).isEqualTo(3) it.tasks[0].apply { @@ -702,7 +702,7 @@ object StartStageHandlerTest : SubjectSpek({ } it("starts the stage") { - verify(repository, times(2)).storeStage( + verify(repository).storeStage( check { assertThat(it.type).isEqualTo("bar") assertThat(it.status).isEqualTo(RUNNING) @@ -712,7 +712,7 @@ object StartStageHandlerTest : SubjectSpek({ } it("attaches a task to the stage") { - verify(repository, times(2)).storeStage( + verify(repository).storeStage( check { assertThat(it.tasks.size).isEqualTo(1) it.tasks.first().apply { @@ -793,12 +793,20 @@ object StartStageHandlerTest : SubjectSpek({ } it("attaches the exception to the stage context") { - verify(repository, times(2)).storeStage( + verify(repository).storeStage( check { assertThat(it.context["exception"]).isEqualTo(exceptionDetails) } ) } + + it("updates the stage with a non-default start time") { + verify(repository).storeStage( + check { + assertThat(it.startTime).isPositive() + } + ) + } } and("only the branch should fail") { @@ -825,7 +833,7 @@ object StartStageHandlerTest : SubjectSpek({ } it("attaches the exception to the stage context") { - verify(repository, times(2)).storeStage( + verify(repository).storeStage( check { assertThat(it.context["exception"]).isEqualTo(exceptionDetails) } @@ -833,12 +841,20 @@ object StartStageHandlerTest : SubjectSpek({ } it("attaches flag to the stage context to indicate that before stage planning failed") { - verify(repository, times(2)).storeStage( + verify(repository).storeStage( check { assertThat(it.context["beforeStagePlanningFailed"]).isEqualTo(true) } ) } + + it("updates the stage with a non-default start time") { + verify(repository).storeStage( + check { + assertThat(it.startTime).isPositive() + } + ) + } } and("the branch should be allowed to continue") { @@ -865,7 +881,7 @@ object StartStageHandlerTest : SubjectSpek({ } it("attaches the exception to the stage context") { - verify(repository, times(2)).storeStage( + verify(repository).storeStage( check { assertThat(it.context["exception"]).isEqualTo(exceptionDetails) } @@ -873,12 +889,20 @@ object StartStageHandlerTest : SubjectSpek({ } it("attaches flag to the stage context to indicate that before stage planning failed") { - verify(repository, times(2)).storeStage( + verify(repository).storeStage( check { assertThat(it.context["beforeStagePlanningFailed"]).isEqualTo(true) } ) } + + it("updates the stage with a non-default start time") { + verify(repository).storeStage( + check { + assertThat(it.startTime).isPositive() + } + ) + } } } @@ -929,7 +953,7 @@ object StartStageHandlerTest : SubjectSpek({ } it("updates the stage status") { - verify(repository, times(2)).storeStage( + verify(repository).storeStage( check { assertThat(it.status).isEqualTo(RUNNING) assertThat(it.startTime).isEqualTo(clock.millis()) @@ -938,7 +962,7 @@ object StartStageHandlerTest : SubjectSpek({ } it("attaches tasks to the stage") { - verify(repository, times(2)).storeStage( + verify(repository).storeStage( check { assertThat(it.tasks.size).isEqualTo(1) it.tasks.first().apply {