@@ -22,6 +22,11 @@ function expectIsPingResponse (obj) {
2222 expect ( obj . text ) . to . be . a ( 'string' )
2323}
2424
25+ // Determine if a ping response object is a pong, or something else, like a status message
26+ function isPong ( pingResponse ) {
27+ return Boolean ( pingResponse && pingResponse . success && ! pingResponse . text )
28+ }
29+
2530module . exports = ( common ) => {
2631 describe ( '.ping' , function ( ) {
2732 let ipfsdA
@@ -57,7 +62,7 @@ module.exports = (common) => {
5762 ipfsdA . ping ( ipfsdB . peerId . id , { count } , ( err , responses ) => {
5863 expect ( err ) . to . not . exist ( )
5964 responses . forEach ( expectIsPingResponse )
60- const pongs = responses . filter ( r => Boolean ( r . time ) )
65+ const pongs = responses . filter ( isPong )
6166 expect ( pongs . length ) . to . equal ( count )
6267 done ( )
6368 } )
@@ -94,10 +99,10 @@ module.exports = (common) => {
9499 const count = 3
95100 pull (
96101 ipfsdA . pingPullStream ( ipfsdB . peerId . id , { count } ) ,
97- pull . drain ( ( { success , time } ) => {
98- expect ( success ) . to . be . true ( )
102+ pull . drain ( ( res ) => {
103+ expect ( res . success ) . to . be . true ( )
99104 // It's a pong
100- if ( time ) {
105+ if ( isPong ( res ) ) {
101106 packetNum ++
102107 }
103108 } , ( err ) => {
@@ -159,10 +164,10 @@ module.exports = (common) => {
159164 ipfsdA . pingReadableStream ( ipfsdB . peerId . id , { count } ) ,
160165 new Writable ( {
161166 objectMode : true ,
162- write ( { success , time } , enc , cb ) {
163- expect ( success ) . to . be . true ( )
167+ write ( res , enc , cb ) {
168+ expect ( res . success ) . to . be . true ( )
164169 // It's a pong
165- if ( time ) {
170+ if ( isPong ( res ) ) {
166171 packetNum ++
167172 }
168173
0 commit comments