Skip to content

Commit

Permalink
Fixing status flaky test
Browse files Browse the repository at this point in the history
There is a chance that status is invoked over a process instance that
has been finished, but the container kogito process instance does not
know yet, even if processcompleted listener has been executed (and thats
the issue)

Although this can be fixed by altering the order in which the different
listener are invoked (which might probably have other undesired effect),
I do not see a reason why status should not be read from underlying
process instance, if present.

Probably processInstance field should be embedded into an atomic
reference, but volatile might have the same effect with few code
changes.
  • Loading branch information
fjtirado committed Nov 14, 2024
1 parent 34a4323 commit dfd99df
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public abstract class AbstractProcessInstance<T extends Model> implements Proces
protected final T variables;
protected final AbstractProcess<T> process;
protected InternalProcessRuntime rt;
protected WorkflowProcessInstance processInstance;
protected volatile WorkflowProcessInstance processInstance;

protected Integer status;

Expand Down Expand Up @@ -334,7 +334,7 @@ public T variables() {

@Override
public int status() {
return status;
return processInstance != null ? processInstance.getState() : status;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -400,8 +400,7 @@ public void testEventBasedSplit2() throws Exception {
org.kie.kogito.process.ProcessInstance<EventBasedSplit2Model> instanceTimer = processDefinition.createInstance(modelTimer);
instanceTimer.start();
assertThat(instanceTimer.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_ACTIVE);
assertThat(countDownListener.waitTillCompleted(15000)).isTrue();
assertThat(instanceYes.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_COMPLETED);
assertThat(countDownListener.waitTillCompleted()).isTrue();
assertThat(instanceTimer.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_COMPLETED);
}

Expand Down

0 comments on commit dfd99df

Please sign in to comment.