EventEmitter(cluster) emitting twice in test case

249 views
Skip to first unread message

Prajwal Manjunath

unread,
May 29, 2013, 6:30:19 AM5/29/13
to nod...@googlegroups.com
I'm trying to test a cluster which forks off three children. When one of them dies, the master replaces that worker with a new fork. I'm using Mocha with Sinon stubs for testing.

I'm stubbing out the cluster's "fork" method. The first test case which checks that it is called thrice (for 3 workers) works fine.

The second test case, which simulates a worker death with "cluster.emit('exit')" should cause master to fork once, but Sinon says it is getting called twice. Why is this happening?

Floby

unread,
May 30, 2013, 4:39:18 AM5/30/13
to nod...@googlegroups.com
You could try and log the worker.id to see if it's really the same worker dying.

Prajwal Manjunath

unread,
May 30, 2013, 4:45:53 AM5/30/13
to nod...@googlegroups.com
It is. I mean, there are no "real" workers, I'm only simulating it with a fake object with a fake id, and the console.log inside the cluster exit handler prints the same id twice.


--
--
Job Board: http://jobs.nodejs.org/
Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nod...@googlegroups.com
To unsubscribe from this group, send email to
nodejs+un...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
 
---
You received this message because you are subscribed to a topic in the Google Groups "nodejs" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/nodejs/DiezT83XYWg/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to nodejs+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Sam Roberts

unread,
May 30, 2013, 1:43:45 PM5/30/13
to nod...@googlegroups.com
On Thu, May 30, 2013 at 1:45 AM, Prajwal Manjunath
<prajw...@gmail.com> wrote:
> It is. I mean, there are no "real" workers, I'm only simulating it with a
> fake object with a fake id, and the console.log inside the cluster exit
> handler prints the same id twice.

Maybe once when you fake it, once when it really dies?

Why not have the worker really die in your test, sounds like what you
are seeing is an artifact of your test setup, and you messing with
emitting messages only cluster expects to emit.

Sam

Floby

unread,
Jun 3, 2013, 8:56:31 AM6/3/13
to nod...@googlegroups.com
It seems to me you mocked your tests too much and now your code is mocking you back ;)


On Wednesday, 29 May 2013 12:30:19 UTC+2, Prajwal Manjunath wrote:
Reply all
Reply to author
Forward
0 new messages