visionmedia/mocha — Issue #309: Do suites running in parallel cause timing issues with the event emitter?
Author: goloroden
Created: 2012-03-09 12:38:56+00:00
State: open

Let's assume you've got a singleton that you want to test.
You write several tests, and since you have different scenarios of test cases, you split them using suites.

Now today we've had the effect that one of these tests blew up with a "done called multiple times" error.

Actually, we've tackled it down to an eventing problem (event in the sense of event emitter):
- In both tests we subscribed to an event using once
- Due to the fact that tests in different suites seem to run in parallel, it is not guaranteed that the test that causes raising the event is the (only) one whose on function is called when the event is raised - even if you use once to subscribe to the event
- This possibly results in event handlers called in the context of another test, which means this test's done function gets called multiple times

Apparently it's a timing issue.

One might argue that it's wrong to use a singleton here, but I think that besides our problem today several other people might have this problem as well.

One possible solution would be to run all tests serialized, or to run each test in a single process.

What do you think about this issue, and the possible solutions?
Is there a recommended way to resolve it (i.e. did we do anything wrong), or might it be a viable improvement?