@@ -24,27 +24,13 @@ const config = {
24
24
}
25
25
26
26
describe . only ( 'ping' , function ( ) {
27
- this . timeout ( 80 * 1000 )
28
-
27
+ this . timeout ( 60 * 1000 )
29
28
let ipfsdA
30
29
let ipfsdB
30
+ let bMultiaddr
31
31
let ipfsdBId
32
32
let cli
33
33
34
- before ( function ( done ) {
35
- this . timeout ( 60 * 1000 )
36
-
37
- df . spawn ( {
38
- exec : './src/cli/bin.js' ,
39
- config,
40
- initoptions : { bits : 512 }
41
- } , ( err , _ipfsd ) => {
42
- expect ( err ) . to . not . exist ( )
43
- ipfsdA = _ipfsd
44
- done ( )
45
- } )
46
- } )
47
-
48
34
before ( ( done ) => {
49
35
this . timeout ( 60 * 1000 )
50
36
series ( [
@@ -62,38 +48,102 @@ describe.only('ping', function () {
62
48
( cb ) => {
63
49
ipfsdB . api . id ( ( err , peerInfo ) => {
64
50
expect ( err ) . to . not . exist ( )
65
- console . log ( peerInfo )
66
51
ipfsdBId = peerInfo . id
52
+ bMultiaddr = peerInfo . addresses [ 0 ]
67
53
cb ( )
68
54
} )
69
55
}
70
56
] , done )
71
57
} )
72
58
73
- after ( ( done ) => ipfsdA . stop ( done ) )
74
- after ( ( done ) => ipfsdB . stop ( done ) )
59
+ before ( function ( done ) {
60
+ this . timeout ( 60 * 1000 )
61
+
62
+ df . spawn ( {
63
+ exec : './src/cli/bin.js' ,
64
+ config,
65
+ initoptions : { bits : 512 }
66
+ } , ( err , _ipfsd ) => {
67
+ expect ( err ) . to . not . exist ( )
68
+ ipfsdA = _ipfsd
69
+ ipfsdA . api . swarm . connect ( bMultiaddr , done )
70
+ } )
71
+ } )
75
72
76
73
before ( ( done ) => {
74
+ this . timeout ( 60 * 1000 )
77
75
cli = ipfsExec ( ipfsdA . repoPath )
78
76
done ( )
79
77
} )
80
78
79
+ after ( ( done ) => ipfsdA . stop ( done ) )
80
+ after ( ( done ) => ipfsdB . stop ( done ) )
81
+
81
82
it ( 'ping host' , ( done ) => {
83
+ this . timeout ( 60 * 1000 )
82
84
const ping = cli ( `ping ${ ipfsdBId } ` )
83
85
const result = [ ]
84
- ping . stdout . on ( 'data' , ( packet ) => {
85
- console . log ( 'ON DATA' )
86
- result . push ( packet . toString ( ) )
86
+ ping . stdout . on ( 'data' , ( output ) => {
87
+ const packets = output . toString ( ) . split ( '\n' ) . slice ( 0 , - 1 )
88
+ result . push ( ... packets )
87
89
} )
88
90
89
- ping . stdout . on ( 'end' , ( c ) => {
90
- console . log ( 'END' , result )
91
+ ping . stdout . on ( 'end' , ( ) => {
92
+ expect ( result ) . to . have . lengthOf ( 12 )
93
+ expect ( result [ 0 ] ) . to . equal ( `PING ${ ipfsdBId } ` )
94
+ for ( let i = 1 ; i < 11 ; i ++ ) {
95
+ expect ( result [ i ] ) . to . match ( / ^ P o n g r e c e i v e d : t i m e = \d + m s $ / )
96
+ }
97
+ expect ( result [ 11 ] ) . to . match ( / ^ A v e r a g e l a t e n c y : \d + ( .\d + ) ? m s $ / )
91
98
done ( )
92
99
} )
93
100
94
101
ping . catch ( ( err ) => {
95
102
expect ( err ) . to . not . exist ( )
103
+ } )
104
+ } )
105
+
106
+ it ( 'ping host with --n option' , ( done ) => {
107
+ this . timeout ( 60 * 1000 )
108
+ const ping = cli ( `ping --n 1 ${ ipfsdBId } ` )
109
+ const result = [ ]
110
+ ping . stdout . on ( 'data' , ( output ) => {
111
+ const packets = output . toString ( ) . split ( '\n' ) . slice ( 0 , - 1 )
112
+ result . push ( ...packets )
113
+ } )
114
+
115
+ ping . stdout . on ( 'end' , ( ) => {
116
+ expect ( result ) . to . have . lengthOf ( 3 )
117
+ expect ( result [ 0 ] ) . to . equal ( `PING ${ ipfsdBId } ` )
118
+ expect ( result [ 1 ] ) . to . match ( / ^ P o n g r e c e i v e d : t i m e = \d + m s $ / )
119
+ expect ( result [ 2 ] ) . to . match ( / ^ A v e r a g e l a t e n c y : \d + ( .\d + ) ? m s $ / )
96
120
done ( )
97
121
} )
122
+
123
+ ping . catch ( ( err ) => {
124
+ expect ( err ) . to . not . exist ( )
125
+ } )
126
+ } )
127
+
128
+ it ( 'ping host with --count option' , ( done ) => {
129
+ this . timeout ( 60 * 1000 )
130
+ const ping = cli ( `ping --count 1 ${ ipfsdBId } ` )
131
+ const result = [ ]
132
+ ping . stdout . on ( 'data' , ( output ) => {
133
+ const packets = output . toString ( ) . split ( '\n' ) . slice ( 0 , - 1 )
134
+ result . push ( ...packets )
135
+ } )
136
+
137
+ ping . stdout . on ( 'end' , ( ) => {
138
+ expect ( result ) . to . have . lengthOf ( 3 )
139
+ expect ( result [ 0 ] ) . to . equal ( `PING ${ ipfsdBId } ` )
140
+ expect ( result [ 1 ] ) . to . match ( / ^ P o n g r e c e i v e d : t i m e = \d + m s $ / )
141
+ expect ( result [ 2 ] ) . to . match ( / ^ A v e r a g e l a t e n c y : \d + ( .\d + ) ? m s $ / )
142
+ done ( )
143
+ } )
144
+
145
+ ping . catch ( ( err ) => {
146
+ expect ( err ) . to . not . exist ( )
147
+ } )
98
148
} )
99
149
} )
0 commit comments