Skip to content

Commit

Permalink
test(engine): cancel jobs with incidents
Browse files Browse the repository at this point in the history
This adds a regression test against activating jobs of cancelled process
instances, by making sure they are cancelled (i.e. deleted).

In this specific case, an uncaught error was thrown on a job which led
to an UNHANDLED_ERROR_EVENT incident. When the process instance is
cancelled, the job was not called, but instead was made activatable
again. This happened, because the incident was resolved as part of the
process instance termination logic. Instead, we should guarantee that
the job is cancelled. A cancelled job can no longer be made
re-activatable. This is a terminal state for jobs, because a cancelled
job is a deleted job.

See #8588 for more details.

(cherry picked from commit d43c344)
  • Loading branch information
korthout committed Apr 28, 2022
1 parent e84b007 commit 310e4c4
Showing 1 changed file with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import io.camunda.zeebe.protocol.record.Record;
import io.camunda.zeebe.protocol.record.RecordType;
import io.camunda.zeebe.protocol.record.RejectionType;
import io.camunda.zeebe.protocol.record.intent.IncidentIntent;
import io.camunda.zeebe.protocol.record.intent.JobIntent;
import io.camunda.zeebe.protocol.record.intent.ProcessInstanceIntent;
import io.camunda.zeebe.protocol.record.value.BpmnElementType;
Expand Down Expand Up @@ -447,4 +448,40 @@ public void shouldWriteEntireEventOnCancel() {
// then
assertThat(canceledRecord.getValue()).isEqualTo(activatedEvent.getValue());
}

/**
* Regression test against activating jobs of cancelled process instances
*
* <p>See: https://github.com/camunda/zeebe/issues/8588
*/
@Test
public void shouldCancelJobsWithIncidents() {
// given
final var processInstanceKey = ENGINE.processInstance().ofBpmnProcessId("PROCESS").create();
final var job = ENGINE.job().ofInstance(processInstanceKey).withType("test").throwError();
assertThat(
RecordingExporter.incidentRecords(IncidentIntent.CREATED)
.withProcessInstanceKey(processInstanceKey)
.withJobKey(job.getKey())
.findAny())
.describedAs("Expect an incident on the job")
.isPresent();

// when
ENGINE.processInstance().withInstanceKey(processInstanceKey).cancel();
assertThat(
RecordingExporter.processInstanceRecords()
.withElementType(BpmnElementType.PROCESS)
.withProcessInstanceKey(processInstanceKey)
.limitToProcessInstanceTerminated()
.findAny())
.describedAs("Wait until the process instance has terminated")
.isPresent();

// then
assertThat(
RecordingExporter.jobRecords(JobIntent.CANCELED).withRecordKey(job.getKey()).findAny())
.describedAs("Expect that the job is cancelled")
.isPresent();
}
}

0 comments on commit 310e4c4

Please sign in to comment.