Skip to content

Commit

Permalink
Fixing status flaky test (apache#3777)
Browse files Browse the repository at this point in the history
* Fixing status flaky test

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.

* Try changing order of listeners
  • Loading branch information
fjtirado authored and rgdoliveira committed Nov 18, 2024
1 parent e7837be commit 1fe2806
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 @@ -442,8 +442,6 @@ public void setState(final int state, String outcome) {

removeEventListeners();
processRuntime.getProcessInstanceManager().removeProcessInstance(this);
processRuntime.getProcessEventSupport().fireAfterProcessCompleted(this, kruntime);

if (isSignalCompletion()) {

List<KogitoEventListener> listeners = eventListeners.get("processInstanceCompleted:" + getStringId());
Expand All @@ -455,6 +453,8 @@ public void setState(final int state, String outcome) {

processRuntime.getSignalManager().signalEvent("processInstanceCompleted:" + getStringId(), this);
}
processRuntime.getProcessEventSupport().fireAfterProcessCompleted(this, kruntime);

} else {
super.setState(state, outcome);
}
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 1fe2806

Please sign in to comment.