@@ -22,6 +22,11 @@ function expectIsPingResponse (obj) {
22
22
expect ( obj . text ) . to . be . a ( 'string' )
23
23
}
24
24
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
+
25
30
module . exports = ( common ) => {
26
31
describe ( '.ping' , function ( ) {
27
32
let ipfsdA
@@ -57,7 +62,7 @@ module.exports = (common) => {
57
62
ipfsdA . ping ( ipfsdB . peerId . id , { count } , ( err , responses ) => {
58
63
expect ( err ) . to . not . exist ( )
59
64
responses . forEach ( expectIsPingResponse )
60
- const pongs = responses . filter ( r => Boolean ( r . time ) )
65
+ const pongs = responses . filter ( isPong )
61
66
expect ( pongs . length ) . to . equal ( count )
62
67
done ( )
63
68
} )
@@ -94,10 +99,10 @@ module.exports = (common) => {
94
99
const count = 3
95
100
pull (
96
101
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 ( )
99
104
// It's a pong
100
- if ( time ) {
105
+ if ( isPong ( res ) ) {
101
106
packetNum ++
102
107
}
103
108
} , ( err ) => {
@@ -159,10 +164,10 @@ module.exports = (common) => {
159
164
ipfsdA . pingReadableStream ( ipfsdB . peerId . id , { count } ) ,
160
165
new Writable ( {
161
166
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 ( )
164
169
// It's a pong
165
- if ( time ) {
170
+ if ( isPong ( res ) ) {
166
171
packetNum ++
167
172
}
168
173
0 commit comments