Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(stage): Handle SKIPPED tasks and synthetic stages #3837

Merged
merged 4 commits into from
Jul 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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