Skip to content

Commit

Permalink
Do not set cancel as true in a reset (#10228)
Browse files Browse the repository at this point in the history
  • Loading branch information
benmoriceau authored Feb 9, 2022
1 parent dedd1ea commit c61b8c2
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public void run(final ConnectionUpdaterInput connectionUpdaterInput) throws Retr
// When cancelling a reset, we endure that the next workflow won't be a reset.
// We are using a specific workflow state for that, this makes the set of the fact that we are going
// to continue as a reset testable.
if (workflowState.isResetConnection() && !workflowState.isCancelled()) {
if (workflowState.isCancelledForReset()) {
workflowState.setContinueAsReset(true);
connectionUpdaterInput.setJobId(null);
connectionUpdaterInput.setAttemptNumber(1);
Expand All @@ -205,7 +205,7 @@ public void run(final ConnectionUpdaterInput connectionUpdaterInput) throws Retr
final ConnectionDeletionInput connectionDeletionInput = new ConnectionDeletionInput(connectionUpdaterInput.getConnectionId());
connectionDeletionActivity.deleteConnection(connectionDeletionInput);
return;
} else if (workflowState.isCancelled()) {
} else if (workflowState.isCancelled() || workflowState.isCancelledForReset()) {
jobCreationAndStatusUpdateActivity.jobCancelled(new JobCancelledInput(
maybeJobId.get(),
maybeAttemptId.get(),
Expand Down Expand Up @@ -301,7 +301,8 @@ public void connectionUpdated() {
public void resetConnection() {
workflowState.setResetConnection(true);
if (workflowState.isRunning()) {
cancelJob();
workflowState.setCancelledForReset(true);
syncWorkflowCancellationScope.cancel();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public WorkflowState(final UUID id, final WorkflowStateChangedListener stateChan
private boolean failed = false;
private boolean resetConnection = false;
private boolean continueAsReset = false;
private boolean cancelledForReset = false;

public void setRunning(final boolean running) {
final ChangedStateEvent event = new ChangedStateEvent(
Expand Down Expand Up @@ -95,6 +96,14 @@ public void setContinueAsReset(final boolean continueAsReset) {
this.continueAsReset = continueAsReset;
}

public void setCancelledForReset(final boolean cancelledForReset) {
final ChangedStateEvent event = new ChangedStateEvent(
StateField.CANCELLED_FOR_RESET,
cancelledForReset);
stateChangedListener.addEvent(id, event);
this.cancelledForReset = cancelledForReset;
}

public void reset() {
this.setRunning(false);
this.setDeleted(false);
Expand All @@ -104,6 +113,7 @@ public void reset() {
this.setFailed(false);
this.setResetConnection(false);
this.setContinueAsReset(false);
this.setCancelledForReset(false);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ enum StateField {
UPDATED,
FAILED,
RESET,
CONTINUE_AS_RESET
CONTINUE_AS_RESET,
CANCELLED_FOR_RESET
}

@Value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,10 @@ public void resetCancelRunningWorkflow() {

final Queue<ChangedStateEvent> events = testStateListener.events(testId);

Assertions.assertThat(events)
.filteredOn(changedStateEvent -> changedStateEvent.getField() == StateField.CANCELLED_FOR_RESET && changedStateEvent.isValue())
.hasSizeGreaterThanOrEqualTo(1);

Assertions.assertThat(events)
.filteredOn(changedStateEvent -> changedStateEvent.getField() == StateField.RESET && changedStateEvent.isValue())
.hasSizeGreaterThanOrEqualTo(1);
Expand Down

0 comments on commit c61b8c2

Please sign in to comment.