Skip to content

Commit

Permalink
perf(repository): Remove duplicate storeStage call (#4795)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
kirangodishala and Daniel Zheng authored Nov 11, 2024
1 parent be75ab5 commit 9e2d2c6
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ object StartStageHandlerTest : SubjectSpek<StartStageHandler>({
}

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())
Expand All @@ -171,7 +171,7 @@ object StartStageHandlerTest : SubjectSpek<StartStageHandler>({
}

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 {
Expand Down Expand Up @@ -222,7 +222,7 @@ object StartStageHandlerTest : SubjectSpek<StartStageHandler>({
}

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())
Expand Down Expand Up @@ -267,7 +267,7 @@ object StartStageHandlerTest : SubjectSpek<StartStageHandler>({
}

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())
Expand Down Expand Up @@ -312,7 +312,7 @@ object StartStageHandlerTest : SubjectSpek<StartStageHandler>({
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 {
Expand Down Expand Up @@ -702,7 +702,7 @@ object StartStageHandlerTest : SubjectSpek<StartStageHandler>({
}

it("starts the stage") {
verify(repository, times(2)).storeStage(
verify(repository).storeStage(
check {
assertThat(it.type).isEqualTo("bar")
assertThat(it.status).isEqualTo(RUNNING)
Expand All @@ -712,7 +712,7 @@ object StartStageHandlerTest : SubjectSpek<StartStageHandler>({
}

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 {
Expand Down Expand Up @@ -793,12 +793,20 @@ object StartStageHandlerTest : SubjectSpek<StartStageHandler>({
}

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") {
Expand All @@ -825,20 +833,28 @@ object StartStageHandlerTest : SubjectSpek<StartStageHandler>({
}

it("attaches the exception to the stage context") {
verify(repository, times(2)).storeStage(
verify(repository).storeStage(
check {
assertThat(it.context["exception"]).isEqualTo(exceptionDetails)
}
)
}

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") {
Expand All @@ -865,20 +881,28 @@ object StartStageHandlerTest : SubjectSpek<StartStageHandler>({
}

it("attaches the exception to the stage context") {
verify(repository, times(2)).storeStage(
verify(repository).storeStage(
check {
assertThat(it.context["exception"]).isEqualTo(exceptionDetails)
}
)
}

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()
}
)
}
}
}

Expand Down Expand Up @@ -929,7 +953,7 @@ object StartStageHandlerTest : SubjectSpek<StartStageHandler>({
}

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())
Expand All @@ -938,7 +962,7 @@ object StartStageHandlerTest : SubjectSpek<StartStageHandler>({
}

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 {
Expand Down

0 comments on commit 9e2d2c6

Please sign in to comment.