From dfd99dff0d3e32c460ef119da28741f18b46c0f2 Mon Sep 17 00:00:00 2001 From: Francisco Javier Tirado Sarti Date: Thu, 14 Nov 2024 13:08:59 +0100 Subject: [PATCH] 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. --- .../org/kie/kogito/process/impl/AbstractProcessInstance.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/kie/kogito/process/impl/AbstractProcessInstance.java b/jbpm/jbpm-flow/src/main/java/org/kie/kogito/process/impl/AbstractProcessInstance.java index 106208afb05..c680fd1ef70 100644 --- a/jbpm/jbpm-flow/src/main/java/org/kie/kogito/process/impl/AbstractProcessInstance.java +++ b/jbpm/jbpm-flow/src/main/java/org/kie/kogito/process/impl/AbstractProcessInstance.java @@ -85,7 +85,7 @@ public abstract class AbstractProcessInstance implements Proces protected final T variables; protected final AbstractProcess process; protected InternalProcessRuntime rt; - protected WorkflowProcessInstance processInstance; + protected volatile WorkflowProcessInstance processInstance; protected Integer status; @@ -334,7 +334,7 @@ public T variables() { @Override public int status() { - return status; + return processInstance != null ? processInstance.getState() : status; } @Override 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); }