From 1fe2806d2848410fc91f1d2d4b26b6d3db199fbc Mon Sep 17 00:00:00 2001 From: Francisco Javier Tirado Sarti <65240126+fjtirado@users.noreply.github.com> Date: Fri, 15 Nov 2024 15:24:00 +0100 Subject: [PATCH] Fixing status flaky test (#3777) * 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 --- .../workflow/instance/impl/WorkflowProcessInstanceImpl.java | 4 ++-- .../test/java/org/jbpm/bpmn2/StandaloneBPMNProcessTest.java | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/instance/impl/WorkflowProcessInstanceImpl.java b/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/instance/impl/WorkflowProcessInstanceImpl.java index e185f6d0197..27a67f296e1 100755 --- a/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/instance/impl/WorkflowProcessInstanceImpl.java +++ b/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/instance/impl/WorkflowProcessInstanceImpl.java @@ -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 listeners = eventListeners.get("processInstanceCompleted:" + getStringId()); @@ -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); } diff --git a/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/StandaloneBPMNProcessTest.java b/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/StandaloneBPMNProcessTest.java index de8df91a30c..e77cbfa99a8 100755 --- a/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/StandaloneBPMNProcessTest.java +++ b/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/StandaloneBPMNProcessTest.java @@ -400,8 +400,7 @@ public void testEventBasedSplit2() throws Exception { org.kie.kogito.process.ProcessInstance 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); }