1
+ /* eslint max-nested-callbacks: ["error", 6] */
1
2
/* eslint-env mocha */
2
3
'use strict'
3
4
@@ -15,10 +16,10 @@ const randomFs = require('random-fs')
15
16
const promisify = require ( 'promisify-es6' )
16
17
const rimraf = require ( 'rimraf' )
17
18
const join = require ( 'path' ) . join
18
- const os = require ( 'os' )
19
19
const hat = require ( 'hat' )
20
-
21
- // const isWindows = os.platform() === 'win32'
20
+ const isCi = require ( 'is-ci' )
21
+ const isWindows = require ( 'is-os' ) . isWindows
22
+ const os = require ( 'os' )
22
23
23
24
const rmDir = promisify ( rimraf )
24
25
@@ -47,40 +48,80 @@ const sizes = [
47
48
8 * MB ,
48
49
64 * MB ,
49
50
128 * MB
50
- // 512 * MB,
51
+ // 512 * MB
51
52
// GB
53
+ // 10 * GB,
54
+ // 100 * GB,
55
+ // 1000 * GB
52
56
]
53
57
58
+ if ( isCi ) {
59
+ sizes . push (
60
+ // 512 * MB,
61
+ // GB
62
+ // 10 * GB,
63
+ // 100 * GB,
64
+ // 1000 * GB
65
+ )
66
+ }
67
+
54
68
const dirs = [
55
69
5 ,
56
- 10 ,
57
- 50
70
+ 10
71
+ // 50,
58
72
// 100,
59
- // 1000
73
+ // 1000,
74
+ // 10000
75
+ ]
76
+
77
+ if ( isCi ) {
78
+ dirs . push (
79
+ // 50,
80
+ // 100,
81
+ // 1000
82
+ // 10000
83
+ )
84
+ }
85
+
86
+ const depth = [
87
+ 5 ,
88
+ 10
60
89
]
61
90
62
- const timeout = 240 * 1000
91
+ if ( isCi ) {
92
+ depth . push (
93
+ // 100
94
+ // 1000
95
+ // 10000
96
+ )
97
+ }
98
+
99
+ const min = 60 * 1000
100
+ const timeout = isCi ? 15 * min : 5 * min
63
101
64
- describe . skip ( 'exchange files' , ( ) => {
102
+ describe ( 'exchange files' , ( ) => {
65
103
let goDaemon
104
+ let goDaemon2
66
105
let jsDaemon
67
- let js2Daemon
106
+ let jsDaemon2
68
107
69
108
let nodes
70
109
71
110
before ( function ( done ) {
72
111
this . timeout ( timeout )
73
112
74
113
parallel ( [
114
+ ( cb ) => goDf . spawn ( { initOptions : { bits : 1024 } } , cb ) ,
75
115
( cb ) => goDf . spawn ( { initOptions : { bits : 1024 } } , cb ) ,
76
116
( cb ) => jsDf . spawn ( { type : 'js' , initOptions : { bits : 512 } } , cb ) ,
77
117
( cb ) => jsDf . spawn ( { type : 'js' , initOptions : { bits : 512 } } , cb )
78
118
] , ( err , n ) => {
79
119
expect ( err ) . to . not . exist ( )
80
120
nodes = n
81
121
goDaemon = nodes [ 0 ]
82
- jsDaemon = nodes [ 1 ]
83
- js2Daemon = nodes [ 2 ]
122
+ goDaemon2 = nodes [ 1 ]
123
+ jsDaemon = nodes [ 2 ]
124
+ jsDaemon2 = nodes [ 3 ]
84
125
done ( )
85
126
} )
86
127
} )
@@ -121,7 +162,37 @@ describe.skip('exchange files', () => {
121
162
] , done )
122
163
} )
123
164
124
- it ( 'connect js <-> js' , function ( done ) {
165
+ it ( 'connect go <-> go2' , function ( done ) {
166
+ this . timeout ( timeout )
167
+
168
+ let goId
169
+ let go2Id
170
+
171
+ series ( [
172
+ ( cb ) => parallel ( [
173
+ ( cb ) => goDaemon . api . id ( cb ) ,
174
+ ( cb ) => goDaemon2 . api . id ( cb )
175
+ ] , ( err , ids ) => {
176
+ expect ( err ) . to . not . exist ( )
177
+ goId = ids [ 0 ]
178
+ go2Id = ids [ 1 ]
179
+ cb ( )
180
+ } ) ,
181
+ ( cb ) => goDaemon . api . swarm . connect ( go2Id . addresses [ 0 ] , cb ) ,
182
+ ( cb ) => goDaemon2 . api . swarm . connect ( goId . addresses [ 0 ] , cb ) ,
183
+ ( cb ) => parallel ( [
184
+ ( cb ) => goDaemon . api . swarm . peers ( cb ) ,
185
+ ( cb ) => goDaemon2 . api . swarm . peers ( cb )
186
+ ] , ( err , peers ) => {
187
+ expect ( err ) . to . not . exist ( )
188
+ expect ( peers [ 0 ] . map ( ( p ) => p . peer . toB58String ( ) ) ) . to . include ( go2Id . id )
189
+ expect ( peers [ 1 ] . map ( ( p ) => p . peer . toB58String ( ) ) ) . to . include ( goId . id )
190
+ cb ( )
191
+ } )
192
+ ] , done )
193
+ } )
194
+
195
+ it ( 'connect js <-> js2' , function ( done ) {
125
196
this . timeout ( timeout )
126
197
127
198
let jsId
@@ -130,17 +201,17 @@ describe.skip('exchange files', () => {
130
201
series ( [
131
202
( cb ) => parallel ( [
132
203
( cb ) => jsDaemon . api . id ( cb ) ,
133
- ( cb ) => js2Daemon . api . id ( cb )
204
+ ( cb ) => jsDaemon2 . api . id ( cb )
134
205
] , ( err , ids ) => {
135
206
expect ( err ) . to . not . exist ( )
136
207
jsId = ids [ 0 ]
137
208
js2Id = ids [ 1 ]
138
209
cb ( )
139
210
} ) ,
140
- ( cb ) => js2Daemon . api . swarm . connect ( jsId . addresses [ 0 ] , cb ) ,
211
+ ( cb ) => jsDaemon2 . api . swarm . connect ( jsId . addresses [ 0 ] , cb ) ,
141
212
( cb ) => jsDaemon . api . swarm . connect ( js2Id . addresses [ 0 ] , cb ) ,
142
213
( cb ) => parallel ( [
143
- ( cb ) => js2Daemon . api . swarm . peers ( cb ) ,
214
+ ( cb ) => jsDaemon2 . api . swarm . peers ( cb ) ,
144
215
( cb ) => jsDaemon . api . swarm . peers ( cb )
145
216
] , ( err , peers ) => {
146
217
expect ( err ) . to . not . exist ( )
@@ -162,7 +233,7 @@ describe.skip('exchange files', () => {
162
233
( res , cb ) => jsDaemon . api . cat ( res [ 0 ] . hash , cb )
163
234
] , ( err , file ) => {
164
235
expect ( err ) . to . not . exist ( )
165
- expect ( file ) . to . be . eql ( data )
236
+ expect ( file ) . to . eql ( data )
166
237
done ( )
167
238
} )
168
239
} )
@@ -177,85 +248,120 @@ describe.skip('exchange files', () => {
177
248
( res , cb ) => goDaemon . api . cat ( res [ 0 ] . hash , cb )
178
249
] , ( err , file ) => {
179
250
expect ( err ) . to . not . exist ( )
180
- expect ( file ) . to . be . eql ( data )
251
+ expect ( file ) . to . eql ( data )
181
252
done ( )
182
253
} )
183
254
} )
184
255
185
- it ( `js -> js : ${ pretty ( size ) } ` , function ( done ) {
256
+ it ( `js -> js2 : ${ pretty ( size ) } ` , function ( done ) {
186
257
this . timeout ( timeout )
187
258
188
259
const data = crypto . randomBytes ( size )
189
260
190
261
waterfall ( [
191
- ( cb ) => js2Daemon . api . add ( data , cb ) ,
262
+ ( cb ) => jsDaemon2 . api . add ( data , cb ) ,
192
263
( res , cb ) => jsDaemon . api . cat ( res [ 0 ] . hash , cb )
193
264
] , ( err , file ) => {
194
265
expect ( err ) . to . not . exist ( )
195
- expect ( file ) . to . be . eql ( data )
266
+ expect ( file ) . to . eql ( data )
267
+ done ( )
268
+ } )
269
+ } )
270
+
271
+ it ( `go -> go2: ${ pretty ( size ) } ` , function ( done ) {
272
+ this . timeout ( timeout )
273
+
274
+ const data = crypto . randomBytes ( size )
275
+
276
+ waterfall ( [
277
+ ( cb ) => goDaemon . api . add ( data , cb ) ,
278
+ ( res , cb ) => goDaemon2 . api . cat ( res [ 0 ] . hash , cb )
279
+ ] , ( err , file ) => {
280
+ expect ( err ) . to . not . exist ( )
281
+ expect ( file ) . to . eql ( data )
196
282
done ( )
197
283
} )
198
284
} )
199
285
} ) )
200
286
201
- // TODO these tests are not fetching the full dir??
202
- describe ( 'get directory' , ( ) => dirs . forEach ( ( num ) => {
203
- it ( `go -> js: depth: 5, num: ${ num } ` , function ( ) {
287
+ if ( isWindows ) { return }
288
+ // TODO fix dir tests on Windows
289
+
290
+ describe ( 'get directory' , ( ) => depth . forEach ( ( d ) => dirs . forEach ( ( num ) => {
291
+ it ( `go -> js: depth: ${ d } , num: ${ num } ` , function ( ) {
204
292
this . timeout ( timeout )
205
293
206
294
const dir = tmpDir ( )
207
-
208
295
return randomFs ( {
209
296
path : dir ,
210
- depth : 5 ,
297
+ depth : d ,
211
298
number : num
212
299
} ) . then ( ( ) => {
213
300
return goDaemon . api . util . addFromFs ( dir , { recursive : true } )
214
301
} ) . then ( ( res ) => {
215
302
const hash = res [ res . length - 1 ] . hash
216
- return jsDaemon . api . object . get ( hash )
303
+ return jsDaemon . api . files . get ( hash )
217
304
} ) . then ( ( res ) => {
218
305
expect ( res ) . to . exist ( )
219
306
return rmDir ( dir )
220
307
} )
221
308
} )
222
309
223
- it ( `js -> go: depth: 5 , num: ${ num } ` , function ( ) {
310
+ it ( `js -> go: depth: ${ d } , num: ${ num } ` , function ( ) {
224
311
this . timeout ( timeout )
225
312
226
313
const dir = tmpDir ( )
227
314
return randomFs ( {
228
315
path : dir ,
229
- depth : 5 ,
316
+ depth : d ,
230
317
number : num
231
318
} ) . then ( ( ) => {
232
319
return jsDaemon . api . util . addFromFs ( dir , { recursive : true } )
233
320
} ) . then ( ( res ) => {
234
321
const hash = res [ res . length - 1 ] . hash
235
- return goDaemon . api . object . get ( hash )
322
+ return goDaemon . api . files . get ( hash )
236
323
} ) . then ( ( res ) => {
237
324
expect ( res ) . to . exist ( )
238
325
return rmDir ( dir )
239
326
} )
240
327
} )
241
328
242
- it ( `js -> js : depth: 5 , num: ${ num } ` , function ( ) {
329
+ it ( `js -> js2 : depth: ${ d } , num: ${ num } ` , function ( ) {
243
330
this . timeout ( timeout )
244
331
245
332
const dir = tmpDir ( )
246
333
return randomFs ( {
247
334
path : dir ,
248
- depth : 5 ,
335
+ depth : d ,
249
336
number : num
250
337
} ) . then ( ( ) => {
251
- return js2Daemon . api . util . addFromFs ( dir , { recursive : true } )
338
+ return jsDaemon2 . api . util . addFromFs ( dir , { recursive : true } )
252
339
} ) . then ( ( res ) => {
253
340
const hash = res [ res . length - 1 ] . hash
254
- return jsDaemon . api . object . get ( hash )
341
+ return jsDaemon . api . files . get ( hash )
255
342
} ) . then ( ( res ) => {
256
343
expect ( res ) . to . exist ( )
257
344
return rmDir ( dir )
258
345
} )
259
346
} )
260
- } ) )
347
+
348
+ it ( `go -> go2: depth: ${ d } , num: ${ num } ` , function ( ) {
349
+ this . timeout ( timeout )
350
+
351
+ const dir = tmpDir ( )
352
+ return randomFs ( {
353
+ path : dir ,
354
+ depth : d ,
355
+ number : num
356
+ } ) . then ( ( ) => {
357
+ return goDaemon2 . api . util . addFromFs ( dir , { recursive : true } )
358
+ } ) . then ( ( res ) => {
359
+ const hash = res [ res . length - 1 ] . hash
360
+ return goDaemon . api . files . get ( hash )
361
+ } ) . then ( ( res ) => {
362
+ expect ( res ) . to . exist ( )
363
+ return rmDir ( dir )
364
+ } )
365
+ } )
366
+ } ) ) )
261
367
} )
0 commit comments