@@ -61,9 +61,7 @@ module.exports = (common) => {
61
61
} )
62
62
63
63
// for Identify to finish
64
- it ( 'time' , ( done ) => {
65
- setTimeout ( done , 1500 )
66
- } )
64
+ it ( 'time' , ( done ) => setTimeout ( done , 1500 ) )
67
65
68
66
describe ( '.peers' , ( ) => {
69
67
beforeEach ( ( done ) => {
@@ -110,20 +108,23 @@ module.exports = (common) => {
110
108
} )
111
109
} )
112
110
113
- const getConfig = ( addresses ) => {
114
- return {
115
- Addresses : {
116
- Swarm : addresses ,
117
- API : '/ip4/127.0.0.1/tcp/0' ,
118
- Gateway : '/ip4/127.0.0.1/tcp/0'
111
+ describe ( 'Shows connected peers only once' , ( ) => {
112
+ function getConfig ( addrs ) {
113
+ addrs = Array . isArray ( addrs ) ? addrs : [ addrs ]
114
+
115
+ return {
116
+ Addresses : {
117
+ Swarm : addrs ,
118
+ API : '/ip4/127.0.0.1/tcp/0' ,
119
+ Gateway : '/ip4/127.0.0.1/tcp/0'
120
+ }
119
121
}
120
122
}
121
- }
122
- const getRepoPath = ( ) => {
123
- return '/tmp/.ipfs-' + Math . random ( ) . toString ( ) . substring ( 2 , 8 )
124
- }
125
123
126
- describe ( 'Shows connected peers only once' , ( ) => {
124
+ function getRepoPath ( ) {
125
+ return '/tmp/.ipfs-' + Math . random ( ) . toString ( ) . substring ( 2 , 8 ) + Date . now ( )
126
+ }
127
+
127
128
it ( 'Connecting two peers with one address each' , ( done ) => {
128
129
let nodeA
129
130
let nodeB
@@ -152,16 +153,8 @@ module.exports = (common) => {
152
153
cb ( )
153
154
} )
154
155
} ,
155
- ( cb ) => {
156
- nodeA . swarm . connect ( nodeBAddress , ( err ) => {
157
- expect ( err ) . to . not . exist ( )
158
- cb ( )
159
- } )
160
- } ,
161
- ( cb ) => {
162
- // Waiting to make sure nodes are connected
163
- setTimeout ( cb , 1000 )
164
- } ,
156
+ ( cb ) => nodeA . swarm . connect ( nodeBAddress , cb ) ,
157
+ ( cb ) => setTimeout ( cb , 1000 ) , // time for identify
165
158
( cb ) => {
166
159
nodeA . swarm . peers ( ( err , peers ) => {
167
160
expect ( err ) . to . not . exist ( )
@@ -183,14 +176,15 @@ module.exports = (common) => {
183
176
let nodeA
184
177
let nodeB
185
178
let nodeBAddress
179
+
180
+ // TODO: Change to port 0, needs: https://github.com/ipfs/interface-ipfs-core/issues/152
186
181
const configA = getConfig ( [
187
- // TODO: Change to port 0, needs: https://github.com/ipfs/interface-ipfs-core/issues/152
188
- '/ip4/127.0.0.1/tcp/6543' ,
189
- '/ip4/127.0.0.1/tcp/6544'
182
+ '/ip4/127.0.0.1/tcp/16543' ,
183
+ '/ip4/127.0.0.1/tcp/16544'
190
184
] )
191
185
const configB = getConfig ( [
192
- '/ip4/127.0.0.1/tcp/6545 ' ,
193
- '/ip4/127.0.0.1/tcp/6546 '
186
+ '/ip4/127.0.0.1/tcp/26545 ' ,
187
+ '/ip4/127.0.0.1/tcp/26546 '
194
188
] )
195
189
series ( [
196
190
( cb ) => {
@@ -214,16 +208,8 @@ module.exports = (common) => {
214
208
cb ( )
215
209
} )
216
210
} ,
217
- ( cb ) => {
218
- nodeA . swarm . connect ( nodeBAddress , ( err ) => {
219
- expect ( err ) . to . not . exist ( )
220
- cb ( )
221
- } )
222
- } ,
223
- ( cb ) => {
224
- // Waiting to make sure nodes are connected
225
- setTimeout ( cb , 1000 )
226
- } ,
211
+ ( cb ) => nodeA . swarm . connect ( nodeBAddress , cb ) ,
212
+ ( cb ) => setTimeout ( cb , 1000 ) , // time for identify
227
213
( cb ) => {
228
214
nodeA . swarm . peers ( ( err , peers ) => {
229
215
expect ( err ) . to . not . exist ( )
0 commit comments