Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Testing events that fire multiple times #191

Closed
bacchusrx opened this Issue · 2 comments

2 participants

@bacchusrx

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 bacchusrx referenced this issue from a commit in bacchusrx/vows
@bacchusrx bacchusrx [fix] Handle vows for events that execute multiple times (fixes #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.
5da488e
@bacchusrx

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

@indexzero indexzero referenced this issue from a commit
@bacchusrx bacchusrx [fix] Handle vows for events that execute multiple times (fixes #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.
5c0676c
@indexzero
Owner

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

@indexzero indexzero closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.