@@ -8,9 +8,11 @@ var addr = 'tcp://127.0.0.1'
88 , captureAddr = addr + ':5509' ;
99
1010var version = semver . gte ( zmq . version , '3.1.0' ) ;
11+ var testutil = require ( './util' ) ;
1112
1213describe ( 'proxy.xpub-xsub' , function ( ) {
13-
14+ afterEach ( testutil . cleanup ) ;
15+
1416 it ( 'should proxy pub-sub connected to xpub-xsub' , function ( done ) {
1517 if ( ! version ) {
1618 done ( ) ;
@@ -22,18 +24,13 @@ describe('proxy.xpub-xsub', function() {
2224
2325 var sub = zmq . socket ( 'sub' ) ;
2426 var pub = zmq . socket ( 'pub' ) ;
27+ testutil . push_sockets ( frontend , backend , sub , pub ) ;
2528
2629 sub . subscribe ( '' ) ;
2730 sub . on ( 'message' , function ( msg ) {
28-
29- frontend . close ( ) ;
30- backend . close ( ) ;
31- sub . close ( ) ;
32- pub . close ( ) ;
33-
3431 msg . should . be . an . instanceof ( Buffer ) ;
3532 msg . toString ( ) . should . equal ( 'foo' ) ;
36-
33+ console . log ( msg . toString ( ) ) ;
3734 done ( ) ;
3835 } ) ;
3936
@@ -45,7 +42,11 @@ describe('proxy.xpub-xsub', function() {
4542
4643 setTimeout ( function ( ) {
4744 pub . send ( 'foo' ) ;
48- } , 200.0 ) ;
45+ } , 500 ) ;
46+
47+ setTimeout ( function ( ) {
48+ throw Error ( "Timeout" ) ;
49+ } , 10000 ) ;
4950
5051 zmq . proxy ( frontend , backend ) ;
5152
@@ -67,33 +68,24 @@ describe('proxy.xpub-xsub', function() {
6768
6869 var sub = zmq . socket ( 'sub' ) ;
6970 var pub = zmq . socket ( 'pub' ) ;
71+ testutil . push_sockets ( frontend , backend , sub , pub , capture , capSub ) ;
72+
73+ var countdown = testutil . done_countdown ( done , 2 ) ;
7074
7175 sub . subscribe ( '' ) ;
7276 sub . on ( 'message' , function ( msg ) {
73-
74- sub . close ( ) ;
75- pub . close ( ) ;
76- backend . close ( ) ;
77- frontend . close ( ) ;
78-
7977 msg . should . be . an . instanceof ( Buffer ) ;
8078 msg . toString ( ) . should . equal ( 'foo' ) ;
8179
8280 console . log ( msg . toString ( ) ) ;
83-
81+ countdown ( ) ;
8482 } ) ;
8583
8684 capSub . subscribe ( '' ) ;
8785 capSub . on ( 'message' , function ( msg ) {
88-
89- capture . close ( ) ;
90- capSub . close ( ) ;
91-
92- setTimeout ( function ( ) {
93- msg . should . be . an . instanceof ( Buffer ) ;
94- msg . toString ( ) . should . equal ( 'foo' ) ;
95- done ( ) ;
96- } , 100.0 ) ;
86+ msg . should . be . an . instanceof ( Buffer ) ;
87+ msg . toString ( ) . should . equal ( 'foo' ) ;
88+ countdown ( ) ;
9789 } ) ;
9890
9991 capture . bind ( captureAddr , function ( ) {
@@ -106,7 +98,11 @@ describe('proxy.xpub-xsub', function() {
10698
10799 setTimeout ( function ( ) {
108100 pub . send ( 'foo' ) ;
109- } , 200.0 ) ;
101+ } , 500 ) ;
102+
103+ setTimeout ( function ( ) {
104+ throw Error ( "Timeout" ) ;
105+ } , 10000 ) ;
110106
111107 zmq . proxy ( frontend , backend , capture ) ;
112108 } ) ;
@@ -131,6 +127,7 @@ describe('proxy.xpub-xsub', function() {
131127
132128 sub . connect ( frontendAddr ) ;
133129 pub . connect ( backendAddr ) ;
130+ testutil . push_sockets ( frontend , backend , sub , pub ) ;
134131
135132 try {
136133
@@ -141,15 +138,9 @@ describe('proxy.xpub-xsub', function() {
141138 e . message . should . equal ( 'wrong socket order to proxy' ) ;
142139
143140 } finally {
144- frontend . close ( ) ;
145- backend . close ( ) ;
146- pub . close ( ) ;
147- sub . close ( ) ;
148-
149- //allow time for TCP sockets to close
150- setTimeout ( function ( ) {
151- done ( ) ;
152- } , 200 )
141+
142+ done ( ) ;
143+
153144 }
154145 } )
155146} ) ;
0 commit comments