@@ -12,9 +12,10 @@ var test = require('tape')
1212var infoHash = '4cb67059ed6bd08362da625b3ae77f6f4a075705'
1313var peerId = Buffer . from ( '01234567890123456789' )
1414var peerId2 = Buffer . from ( '12345678901234567890' )
15+ var peerId3 = Buffer . from ( '23456789012345678901' )
1516
1617function serverTest ( t , serverType , serverFamily ) {
17- t . plan ( 30 )
18+ t . plan ( 32 )
1819
1920 var hostname = serverFamily === 'inet6'
2021 ? '[::1]'
@@ -23,7 +24,12 @@ function serverTest (t, serverType, serverFamily) {
2324 ? '::1'
2425 : '127.0.0.1'
2526
26- common . createServer ( t , serverType , function ( server ) {
27+ var opts = {
28+ serverType : serverType ,
29+ peersCacheLength : 2
30+ }
31+
32+ common . createServer ( t , opts , function ( server ) {
2733 var port = server [ serverType ] . address ( ) . port
2834 var announceUrl = serverType + '://' + hostname + ':' + port + '/announce'
2935
@@ -103,22 +109,42 @@ function serverTest (t, serverType, serverFamily) {
103109 client2 . once ( 'peer' , function ( addr ) {
104110 t . ok ( addr === hostname + ':6881' || addr === hostname + ':6882' || addr . id === peerId . toString ( 'hex' ) )
105111
106- client2 . stop ( )
107- client2 . once ( 'update' , function ( data ) {
108- t . equal ( data . announce , announceUrl )
109- t . equal ( data . complete , 1 )
110- t . equal ( data . incomplete , 0 )
111- client2 . destroy ( )
112+ swarm . peers . once ( 'evict' , function ( evicted ) {
113+ t . equals ( evicted . value . peerId , peerId . toString ( 'hex' ) )
114+ } )
115+ var client3 = new Client ( {
116+ infoHash : infoHash ,
117+ announce : [ announceUrl ] ,
118+ peerId : peerId3 ,
119+ port : 6880
120+ // wrtc: wrtc
121+ } )
122+ client3 . start ( )
123+
124+ server . once ( 'start' , function ( ) {
125+ t . pass ( 'got start message from client3' )
126+ } )
112127
113- client1 . stop ( )
114- client1 . once ( 'update' , function ( data ) {
128+ client3 . once ( 'update' , function ( ) {
129+ client2 . stop ( )
130+ client2 . once ( 'update' , function ( data ) {
115131 t . equal ( data . announce , announceUrl )
116- t . equal ( data . complete , 0 )
117- t . equal ( data . incomplete , 0 )
118-
119- client1 . destroy ( function ( ) {
120- server . close ( )
121- // if (serverType === 'ws') wrtc.close()
132+ t . equal ( data . complete , 1 )
133+ t . equal ( data . incomplete , 1 )
134+ client2 . destroy ( )
135+
136+ client3 . stop ( )
137+ client3 . once ( 'update' , function ( data ) {
138+ t . equal ( data . announce , announceUrl )
139+ t . equal ( data . complete , 1 )
140+ t . equal ( data . incomplete , 0 )
141+
142+ client3 . destroy ( function ( ) {
143+ client1 . destroy ( function ( ) {
144+ server . close ( )
145+ } )
146+ // if (serverType === 'ws') wrtc.close()
147+ } )
122148 } )
123149 } )
124150 } )
0 commit comments