Hi All,

I'm probably not the first one to raise this topic on this mailing list but
I'm really struggling to run stories concurrently.

I've started my research here:
http://jbehave.org/reference/stable/multi-threading.html but this page is
no good and out of date (ie. it mentions embedder's method "enqueueStory"
which was deprecated long time ago!).


Since yesterday I'm trying to play with the official "Multi-Threading"
example:
https://github.com/jbehave/jbehave-core/tree/master/examples/threads
It works but just partially. It creates any desired number of threads and
then run stories in them but there are two main issues with this example:
* Race conditions
* thread that finishes last overwrites report results of other threads

I slightly modified the aforementioned "threads" example, here's a list of
changes:
* it runs in IDE,
* made it independent from the parent "jbehave-examples" project
* report resources are upnacked when running from CLI
* extended useStoryTimeoutInSecs to 60s
* moved stories from src/main/java/org/jbehave/examples/threads/stories to
src/main/resources/stories as StoryFinder couldn't locate them!
The code is available here:
https://github.com/kowalcj0/jbehave-threads-example


To run tests from CLI:
mvn clean install
(This will also unpack all the report resources)

To run them in IDE (tested with Intelij Idea) simply right click on
"ThreadsStories" class and select run.
(btw. this won't unpack report resources, so the report will be missing all
the styling, but if you run "mvn install" first and then re-run tests from
IDE all the resources will be still in place and only report files will get
updated :) )


To change number of threads:
if you're going to use CLI, then define # of threads in pom.xml
    <properties>
     ...
         <threads>1</threads>
     ...
    </properties>

in case you prefer running tests in IDE:
Set the # of threads in the "ThreadsStories" class constructor.


I'd appreciate any help to build a properly working example of a
multi-threading jbehave project, with no race condition issues and the one
that also generates a proper report.


btw. Here's an excerpt from the log showing the race condition problem
*ConcurrentModificationException*
...

> Scenario: scenario with examples
> Maria starts counting to 5
> Maria says 0 Mississippi (after 0 s)
> Failed to run story stories/another_long.story
> java.util.ConcurrentModificationException
> at java.util.ArrayList$Itr.checkForComodification(ArrayList.java:819)
> at java.util.ArrayList$Itr.next(ArrayList.java:791)
> at
> java.util.Collections$UnmodifiableCollection$1.next(Collections.java:1067)
> at
> org.jbehave.core.reporters.ConcurrentStoryReporter.invokeDelayed(ConcurrentStoryReporter.java:324)
> at
> org.jbehave.core.embedder.PerformableTree.perform(PerformableTree.java:319)
> at
> org.jbehave.core.embedder.StoryManager$EnqueuedStory.call(StoryManager.java:227)
> at
> org.jbehave.core.embedder.StoryManager$EnqueuedStory.call(StoryManager.java:206)
> at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
> at java.util.concurrent.FutureTask.run(FutureTask.java:166)
> at
> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
> at
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
> at java.lang.Thread.run(Thread.java:722)
> Maria says 1 Mississippi (after 1 s)
> Maria says 2 Mississippi (after 2 s)
> Maria says 3 Mississippi (after 3 s)
> Maria says 4 Mississippi (after 4 s)

...


Many thanks,
Janusz

Reply via email to