Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testing events that fire multiple times #191

Closed
bacchusrx opened this issue Feb 12, 2012 · 2 comments
Closed

Testing events that fire multiple times #191

bacchusrx opened this issue Feb 12, 2012 · 2 comments

Comments

@bacchusrx
Copy link

I'm running into an issue with vows for events that fire multiple times. According to @indexzero's comment in #79, firing callbacks multiple times should be possible, so hopefully I'm correct in thinking firing multiple events should also. I'd like to know whether the behaviour I'm seeing is expected, a bug, or if I'm going about it the wrong way.

Basically I'm doing some testing of hook.io hooks, using the new event support from #109/#145, and in some cases I'm testing events that need to fire multiple times, and I have to verify they fired the correct number of times. So, I use a macro to generate a vow for the event that closes over a counter which is incremented each time the vow fires, and another vow that later on checks the counter. So far so good.

What happens is that the batch.honored counter is incremented each time a duplicate event is fired, and so sometimes in tryEnd (in lib/vows/suite.js) this condition fails:

if (batch.honored + batch.broken + batch.errored + batch.pending === batch.total &&
    batch.remaining === 0) {

because there were more vows honored than batch.total (which is incremented once when addVow is called).

The result is that the batch, while passing, hangs indefinitely.

I was able to hack around this temporarily by changing the first === to >= and moving the tally,

Object.keys(batch).forEach(function (k) {
  (k in batch.suite.results) && (batch.suite.results[k] += batch[k]);
});

down into finish().

This didn't break my own tests or the Vows tests, but, it might be better instead to change the way addVow works so that batch.total gets set correctly when dealing with events that fire multiple times.

If this behaviour is supposed to work I can put together a failing test.

bacchusrx added a commit to bacchusrx/vows that referenced this issue Feb 16, 2012
…s#191)

Add failing test for events that fire multiple times.

In `lib/vows/suite.js` add a property `count` to each vow which is incremented
every time the vow is executed.

In `runTest` (in `addVow` in `lib/vows.js`), on each execution increment
`batch.total` if a vow has been executed more than once.
@bacchusrx
Copy link
Author

A test and, I think, a better fix submitted in #193.

indexzero pushed a commit that referenced this issue Nov 22, 2014
Add failing test for events that fire multiple times.

In `lib/vows/suite.js` add a property `count` to each vow which is incremented
every time the vow is executed.

In `runTest` (in `addVow` in `lib/vows.js`), on each execution increment
`batch.total` if a vow has been executed more than once.
@indexzero
Copy link

This is fixed in v0.9.x which will be released shortly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants