jBPM JUnit tests are failing
michael.wagner Jul 20, 2011 5:15 AMHi,
I have downloaded the junit tests from:
First: big thank you for providing so many unit tests! Makes is absolutly clear how to use the api.
Running JBPM2UnitTests.java gives me always one failure in testTimerStart:
junit.framework.AssertionFailedError: expected:<5> but was:<4>
"Correcting" the value to 4 gives a failure in testTimerStartCron:
junit.framework.AssertionFailedError: expected:<5> but was:<6>
"Correcting" the value here to 6 gives no more failures any more.
public void testTimerStartCron() throws Exception { KnowledgeBase kbase = createKnowledgeBase("BPMN2-TimerStartCron.bpmn2"); StatefulKnowledgeSession ksession = createKnowledgeSession(kbase); final List list = new ArrayList(); ksession.addEventListener(new DefaultProcessEventListener() { public void afterProcessStarted(ProcessStartedEvent event) { list.add(event.getProcessInstance().getId()); } }); Thread.sleep(500); for (int i = 0; i < 5; i++) { ksession.fireAllRules(); Thread.sleep(1000); } assertEquals(6, list.size()); } public void testTimerStart() throws Exception { KnowledgeBase kbase = createKnowledgeBase("BPMN2-TimerStart.bpmn2"); StatefulKnowledgeSession ksession = createKnowledgeSession(kbase); final List list = new ArrayList(); ksession.addEventListener(new DefaultProcessEventListener() { public void afterProcessStarted(ProcessStartedEvent event) { list.add(event.getProcessInstance().getId()); } }); Thread.sleep(250); assertEquals(0, list.size()); for (int i = 0; i < 5; i++) { ksession.fireAllRules(); Thread.sleep(500); } assertEquals(4, list.size()); }
Besides that I cannot understand the values by reading the code: what I definitively do not understand is: how can somebody write tests depending on a "Thread.sleep"? Are there no events one could wait for? This gives a situation which is not deterministic! This is because time is not processor time.
Please tell me how the junit tests in these cases could be re-written in a deterministic way.
We are in an automotive area and cannot affort to run software which can not be testet in a deterministic way.
Michael