Permalink
Browse files

fixed hanging testcases on fast Linux machines

  • Loading branch information...
jeremybarnes committed Jan 3, 2013
1 parent 335e307 commit 89376d5459a00f1e71ef27bad918408aeeb8fba5
Showing with 35 additions and 9 deletions.
  1. +16 −4 test/test.socket.pub-sub.filter.js
  2. +19 −5 test/test.socket.pub-sub.js
@@ -26,8 +26,20 @@ sub.on('message', function(msg){
sub.bind('inproc://stuff', function(){
pub.connect('inproc://stuff');
- pub.send('js is cool');
- pub.send('ruby is meh');
- pub.send('py is pretty cool');
- pub.send('luna is cool too');
+
+ // The connect is asynchronous, and messages published to a non-
+ // connected socket are silently dropped. That means that there is
+ // a race between connecting and sending the first message which
+ // causes this test to hang, especially when running on Linux. Even an
+ // inproc:// socket seems to be asynchronous. So instead of
+ // sending straight away, we wait 100ms for the connection to be
+ // established before we start the send. This fixes the observed
+ // hang.
+
+ setTimeout(function() {
+ pub.send('js is cool');
+ pub.send('ruby is meh');
+ pub.send('py is pretty cool');
+ pub.send('luna is cool too');
+ }, 100.0);
});
@@ -25,9 +25,23 @@ sub.on('message', function(msg){
}
});
-sub.bind('inproc://stuff', function(){
- pub.connect('inproc://stuff');
- pub.send('foo');
- pub.send('bar');
- pub.send('baz');
+var addr = "inproc://stuff";
+
+sub.bind(addr, function(){
+ pub.connect(addr);
+
+ // The connect is asynchronous, and messages published to a non-
+ // connected socket are silently dropped. That means that there is
+ // a race between connecting and sending the first message which
+ // causes this test to hang, especially when running on Linux. Even an
+ // inproc:// socket seems to be asynchronous. So instead of
+ // sending straight away, we wait 100ms for the connection to be
+ // established before we start the send. This fixes the observed
+ // hang.
+
+ setTimeout(function() {
+ pub.send('foo');
+ pub.send('bar');
+ pub.send('baz');
+ }, 100.0);
});

0 comments on commit 89376d5

Please sign in to comment.