Skip to content

Commit 9e2d2c6

Browse files
kirangodishalaDaniel Zheng
and
Daniel Zheng
authored
perf(repository): Remove duplicate storeStage call (#4795)
* test(handler): Verify that start time is set Verify that the start time for a stage is set even when we encounter an exception * perf(stage): Remove duplicate storeStage call The duplicate repository.storeStage call was originally added in e872ce8 to ensure that the start time for a stage is set even if the handler encounters an exception. However, even without the extra repository.storeStage, orca still sets the start time for a stage when it encounters an exception. --------- Co-authored-by: Daniel Zheng <d.zheng@salesforce.com>
1 parent be75ab5 commit 9e2d2c6

File tree

2 files changed

+38
-15
lines changed

2 files changed

+38
-15
lines changed

orca-queue/src/main/kotlin/com/netflix/spinnaker/orca/q/handler/StartStageHandler.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ class StartStageHandler(
9595
try {
9696
// Set the startTime in case we throw an exception.
9797
stage.startTime = clock.millis()
98-
repository.storeStage(stage)
9998
stage.plan()
10099
stage.status = RUNNING
101100
repository.storeStage(stage)

orca-queue/src/test/kotlin/com/netflix/spinnaker/orca/q/handler/StartStageHandlerTest.kt

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ object StartStageHandlerTest : SubjectSpek<StartStageHandler>({
162162
}
163163

164164
it("updates the stage status") {
165-
verify(repository, times(2)).storeStage(
165+
verify(repository).storeStage(
166166
check {
167167
assertThat(it.status).isEqualTo(RUNNING)
168168
assertThat(it.startTime).isEqualTo(clock.millis())
@@ -171,7 +171,7 @@ object StartStageHandlerTest : SubjectSpek<StartStageHandler>({
171171
}
172172

173173
it("attaches tasks to the stage") {
174-
verify(repository, times(2)).storeStage(
174+
verify(repository).storeStage(
175175
check {
176176
assertThat(it.tasks.size).isEqualTo(1)
177177
it.tasks.first().apply {
@@ -222,7 +222,7 @@ object StartStageHandlerTest : SubjectSpek<StartStageHandler>({
222222
}
223223

224224
it("updates the stage status") {
225-
verify(repository, times(2)).storeStage(
225+
verify(repository).storeStage(
226226
check {
227227
assertThat(it.status).isEqualTo(RUNNING)
228228
assertThat(it.startTime).isEqualTo(clock.millis())
@@ -267,7 +267,7 @@ object StartStageHandlerTest : SubjectSpek<StartStageHandler>({
267267
}
268268

269269
it("updates the stage status") {
270-
verify(repository, times(2)).storeStage(
270+
verify(repository).storeStage(
271271
check {
272272
assertThat(it.status).isEqualTo(RUNNING)
273273
assertThat(it.startTime).isEqualTo(clock.millis())
@@ -312,7 +312,7 @@ object StartStageHandlerTest : SubjectSpek<StartStageHandler>({
312312
afterGroup(::resetMocks)
313313

314314
it("attaches tasks to the stage") {
315-
verify(repository, times(2)).storeStage(
315+
verify(repository).storeStage(
316316
check {
317317
assertThat(it.tasks.size).isEqualTo(3)
318318
it.tasks[0].apply {
@@ -702,7 +702,7 @@ object StartStageHandlerTest : SubjectSpek<StartStageHandler>({
702702
}
703703

704704
it("starts the stage") {
705-
verify(repository, times(2)).storeStage(
705+
verify(repository).storeStage(
706706
check {
707707
assertThat(it.type).isEqualTo("bar")
708708
assertThat(it.status).isEqualTo(RUNNING)
@@ -712,7 +712,7 @@ object StartStageHandlerTest : SubjectSpek<StartStageHandler>({
712712
}
713713

714714
it("attaches a task to the stage") {
715-
verify(repository, times(2)).storeStage(
715+
verify(repository).storeStage(
716716
check {
717717
assertThat(it.tasks.size).isEqualTo(1)
718718
it.tasks.first().apply {
@@ -793,12 +793,20 @@ object StartStageHandlerTest : SubjectSpek<StartStageHandler>({
793793
}
794794

795795
it("attaches the exception to the stage context") {
796-
verify(repository, times(2)).storeStage(
796+
verify(repository).storeStage(
797797
check {
798798
assertThat(it.context["exception"]).isEqualTo(exceptionDetails)
799799
}
800800
)
801801
}
802+
803+
it("updates the stage with a non-default start time") {
804+
verify(repository).storeStage(
805+
check {
806+
assertThat(it.startTime).isPositive()
807+
}
808+
)
809+
}
802810
}
803811

804812
and("only the branch should fail") {
@@ -825,20 +833,28 @@ object StartStageHandlerTest : SubjectSpek<StartStageHandler>({
825833
}
826834

827835
it("attaches the exception to the stage context") {
828-
verify(repository, times(2)).storeStage(
836+
verify(repository).storeStage(
829837
check {
830838
assertThat(it.context["exception"]).isEqualTo(exceptionDetails)
831839
}
832840
)
833841
}
834842

835843
it("attaches flag to the stage context to indicate that before stage planning failed") {
836-
verify(repository, times(2)).storeStage(
844+
verify(repository).storeStage(
837845
check {
838846
assertThat(it.context["beforeStagePlanningFailed"]).isEqualTo(true)
839847
}
840848
)
841849
}
850+
851+
it("updates the stage with a non-default start time") {
852+
verify(repository).storeStage(
853+
check {
854+
assertThat(it.startTime).isPositive()
855+
}
856+
)
857+
}
842858
}
843859

844860
and("the branch should be allowed to continue") {
@@ -865,20 +881,28 @@ object StartStageHandlerTest : SubjectSpek<StartStageHandler>({
865881
}
866882

867883
it("attaches the exception to the stage context") {
868-
verify(repository, times(2)).storeStage(
884+
verify(repository).storeStage(
869885
check {
870886
assertThat(it.context["exception"]).isEqualTo(exceptionDetails)
871887
}
872888
)
873889
}
874890

875891
it("attaches flag to the stage context to indicate that before stage planning failed") {
876-
verify(repository, times(2)).storeStage(
892+
verify(repository).storeStage(
877893
check {
878894
assertThat(it.context["beforeStagePlanningFailed"]).isEqualTo(true)
879895
}
880896
)
881897
}
898+
899+
it("updates the stage with a non-default start time") {
900+
verify(repository).storeStage(
901+
check {
902+
assertThat(it.startTime).isPositive()
903+
}
904+
)
905+
}
882906
}
883907
}
884908

@@ -929,7 +953,7 @@ object StartStageHandlerTest : SubjectSpek<StartStageHandler>({
929953
}
930954

931955
it("updates the stage status") {
932-
verify(repository, times(2)).storeStage(
956+
verify(repository).storeStage(
933957
check {
934958
assertThat(it.status).isEqualTo(RUNNING)
935959
assertThat(it.startTime).isEqualTo(clock.millis())
@@ -938,7 +962,7 @@ object StartStageHandlerTest : SubjectSpek<StartStageHandler>({
938962
}
939963

940964
it("attaches tasks to the stage") {
941-
verify(repository, times(2)).storeStage(
965+
verify(repository).storeStage(
942966
check {
943967
assertThat(it.tasks.size).isEqualTo(1)
944968
it.tasks.first().apply {

0 commit comments

Comments
 (0)