Skip to content

Commit

Permalink
fix(stage): Handle SKIPPED tasks and synthetic stages (#3837)
Browse files Browse the repository at this point in the history
* fix(stage): Handle SKIPPED tasks and synthetic stages

* fix lint

Co-authored-by: Qijia Wang <qijia.wang@grabtaxi.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
3 people committed Jul 29, 2020
1 parent 1d79c9d commit 2c78d69
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ class CompleteStageHandler(
allStatuses.contains(STOPPED) -> STOPPED
allStatuses.contains(CANCELED) -> CANCELED
allStatuses.contains(FAILED_CONTINUE) -> FAILED_CONTINUE
allStatuses.all { it == SUCCEEDED } -> SUCCEEDED
allStatuses.all { it == SUCCEEDED || it == SKIPPED } -> SUCCEEDED
afterStageStatuses.contains(NOT_STARTED) -> RUNNING // after stages were planned but not run yet
else -> {
log.error("Unhandled condition for stage $id of ${execution.id}, marking as TERMINAL. syntheticStatuses=$syntheticStatuses, taskStatuses=$taskStatuses, planningStatus=$planningStatus, afterStageStatuses=$afterStageStatuses")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,79 @@ object CompleteStageHandlerTest : SubjectSpek<CompleteStageHandler>({
}
}

describe("when a stage had skipped synthetics or tasks") {
given("some tasks were skipped") {
val pipeline = pipeline {
stage {
refId = "1"
type = multiTaskStage.type
multiTaskStage.plan(this)
tasks[0].status = SUCCEEDED
tasks[1].status = SKIPPED
tasks[2].status = SUCCEEDED
status = RUNNING
}
}
val message = CompleteStage(pipeline.stageByRef("1"))

beforeGroup {
whenever(repository.retrieve(PIPELINE, message.executionId)) doReturn pipeline
}

afterGroup(::resetMocks)

on("receiving the message") {
subject.handle(message)
}

it("updates the stage state") {
verify(repository).storeStage(
check {
assertThat(it.status).isEqualTo(SUCCEEDED)
assertThat(it.endTime).isEqualTo(clock.millis())
}
)
}
}

given("some synthetic stages were skipped") {
val pipeline = pipeline {
stage {
refId = "1"
type = stageWithSyntheticBefore.type
stageWithSyntheticBefore.buildBeforeStages(this)
stageWithSyntheticBefore.buildTasks(this)
}
}

val message = CompleteStage(pipeline.stageByRef("1"))

beforeGroup {
pipeline
.stages
.filter { it.syntheticStageOwner == STAGE_BEFORE }
.forEach { it.status = SKIPPED }
pipeline.stageById(message.stageId).tasks.forEach { it.status = SUCCEEDED }
whenever(repository.retrieve(PIPELINE, message.executionId)) doReturn pipeline
}

afterGroup(::resetMocks)

on("receiving the message") {
subject.handle(message)
}

it("updates the stage state") {
verify(repository).storeStage(
check {
assertThat(it.status).isEqualTo(SUCCEEDED)
assertThat(it.endTime).isEqualTo(clock.millis())
}
)
}
}
}

given("a stage had no tasks or before stages") {
but("does have after stages") {
val pipeline = pipeline {
Expand Down

0 comments on commit 2c78d69

Please sign in to comment.