cucumber-attic / gherkin2

A fast Gherkin parser in Ragel (The parser behind Cucumber)
MIT License
381 stars 220 forks source link

JSON Formatter is not thread safe #230

Open joshughes opened 11 years ago

joshughes commented 11 years ago

When running Cucumber tests in parallel only the last RunCukes.java class to be executed writes to the json report. This is a problem for anyone that consumes the report downstream. @rexhoffman mentioned this would be easy to do.

aslakhellesoy commented 11 years ago

I don't think we'll attempt to make any reporters thread safe. I think it's easier to fix Cucumber so it only accesses reporters from a single thread.

WDYT?

rexhoffman commented 11 years ago

Fixing the internals of cucumber-jvm to support multithreading while maintaining the committed to api for reporters/formatters will be difficult at best (some of the implicit contracts about ordering will need to be broken). I'd rather see cucumber-jvm execute in a thread safe way.

To get there, it might be interesting to attempt this by making the json formatter, have it act as an intermediary holder of state, until passing it off to other real formatters. Internal state storage needs to happen somewhere.... the json reporter could become a report aggregator and proxy.

Refactor-rinse-repeat?

ghost commented 10 years ago

In my project we are using parallel test, cucumber and Gherkin gesm to generate the HTML reports. In the project we are using JSONFormatter to write a json, due to multithreaded environment it is giving us malformed JSON every time. Please refer the attachment for the same.

If you have any solution to synchronize the threads while writing on JSON then please suggest us, Tons of thanks in advance. json1

mngenius commented 6 years ago

in Gherkin library, they just need to move to google Gson, whivch is maintaining a ThreadLoacl, instead of their Gson, which uses a HashMap