@@ -36,9 +36,9 @@ function testClientStart (t, serverType) {
3636 client . stop ( )
3737
3838 client . once ( 'update' , function ( ) {
39- server . close ( function ( ) {
40- t . pass ( ' server close' )
41- } )
39+ t . pass ( 'got response to stop' )
40+ server . close ( )
41+ client . destroy ( )
4242 } )
4343 } )
4444
@@ -55,7 +55,7 @@ test('udp: client.start()', function (t) {
5555} )
5656
5757function testClientStop ( t , serverType ) {
58- t . plan ( 4 )
58+ t . plan ( 3 )
5959 common . createServer ( t , serverType , function ( server , announceUrl ) {
6060 parsedTorrent . announce = [ announceUrl ]
6161 var client = new Client ( peerId1 , port , parsedTorrent )
@@ -79,9 +79,8 @@ function testClientStop (t, serverType) {
7979 t . equal ( typeof data . complete , 'number' )
8080 t . equal ( typeof data . incomplete , 'number' )
8181
82- server . close ( function ( ) {
83- t . pass ( 'server close' )
84- } )
82+ server . close ( )
83+ client . destroy ( )
8584 } )
8685 } , 1000 )
8786 } )
@@ -121,9 +120,9 @@ function testClientUpdate (t, serverType) {
121120 client . stop ( )
122121
123122 client . once ( 'update' , function ( ) {
124- server . close ( function ( ) {
125- t . pass ( ' server close' )
126- } )
123+ t . pass ( 'got response to stop' )
124+ server . close ( )
125+ client . destroy ( )
127126 } )
128127 } )
129128 } )
@@ -139,7 +138,7 @@ test('udp: client.update()', function (t) {
139138} )
140139
141140function testClientScrape ( t , serverType ) {
142- t . plan ( 5 )
141+ t . plan ( 4 )
143142 common . createServer ( t , serverType , function ( server , announceUrl ) {
144143 parsedTorrent . announce = [ announceUrl ]
145144 var client = new Client ( peerId1 , port , parsedTorrent )
@@ -158,9 +157,8 @@ function testClientScrape (t, serverType) {
158157 t . equal ( typeof data . incomplete , 'number' )
159158 t . equal ( typeof data . downloaded , 'number' )
160159
161- server . close ( function ( ) {
162- t . pass ( 'server close' )
163- } )
160+ server . close ( )
161+ client . destroy ( )
164162 } )
165163
166164 client . scrape ( )
@@ -176,7 +174,7 @@ test('udp: client.scrape()', function (t) {
176174} )
177175
178176function testClientAnnounceWithNumWant ( t , serverType ) {
179- t . plan ( 1 )
177+ t . plan ( 4 )
180178 common . createServer ( t , serverType , function ( server , announceUrl ) {
181179 parsedTorrent . announce = [ announceUrl ]
182180 var client1 = new Client ( peerId1 , port , parsedTorrent )
@@ -200,10 +198,30 @@ function testClientAnnounceWithNumWant (t, serverType) {
200198 client3 . on ( 'peer' , function ( ) {
201199 t . pass ( 'got one peer (this should only fire once)' )
202200
201+ var num = 3
202+ function tryCloseServer ( ) {
203+ num -= 1
204+ if ( num === 0 ) server . close ( )
205+ }
206+
203207 client1 . stop ( )
208+ client1 . once ( 'update' , function ( ) {
209+ t . pass ( 'got response to stop (client1)' )
210+ client1 . destroy ( )
211+ tryCloseServer ( )
212+ } )
204213 client2 . stop ( )
214+ client2 . once ( 'update' , function ( ) {
215+ t . pass ( 'got response to stop (client2)' )
216+ client2 . destroy ( )
217+ tryCloseServer ( )
218+ } )
205219 client3 . stop ( )
206- server . close ( )
220+ client3 . once ( 'update' , function ( ) {
221+ t . pass ( 'got response to stop (client3)' )
222+ client3 . destroy ( )
223+ tryCloseServer ( )
224+ } )
207225 } )
208226 } )
209227 } )
0 commit comments