1+ /* eslint max-nested-callbacks: ["error", 6] */
12/* eslint-env mocha */
23'use strict'
34
@@ -15,10 +16,10 @@ const randomFs = require('random-fs')
1516const promisify = require ( 'promisify-es6' )
1617const rimraf = require ( 'rimraf' )
1718const join = require ( 'path' ) . join
18- const os = require ( 'os' )
1919const 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' )
2223
2324const rmDir = promisify ( rimraf )
2425
@@ -47,40 +48,80 @@ const sizes = [
4748 8 * MB ,
4849 64 * MB ,
4950 128 * MB
50- // 512 * MB,
51+ // 512 * MB
5152 // GB
53+ // 10 * GB,
54+ // 100 * GB,
55+ // 1000 * GB
5256]
5357
58+ if ( isCi ) {
59+ sizes . push (
60+ // 512 * MB,
61+ // GB
62+ // 10 * GB,
63+ // 100 * GB,
64+ // 1000 * GB
65+ )
66+ }
67+
5468const dirs = [
5569 5 ,
56- 10 ,
57- 50
70+ 10
71+ // 50,
5872 // 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
6089]
6190
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
63101
64- describe . skip ( 'exchange files' , ( ) => {
102+ describe ( 'exchange files' , ( ) => {
65103 let goDaemon
104+ let goDaemon2
66105 let jsDaemon
67- let js2Daemon
106+ let jsDaemon2
68107
69108 let nodes
70109
71110 before ( function ( done ) {
72111 this . timeout ( timeout )
73112
74113 parallel ( [
114+ ( cb ) => goDf . spawn ( { initOptions : { bits : 1024 } } , cb ) ,
75115 ( cb ) => goDf . spawn ( { initOptions : { bits : 1024 } } , cb ) ,
76116 ( cb ) => jsDf . spawn ( { type : 'js' , initOptions : { bits : 512 } } , cb ) ,
77117 ( cb ) => jsDf . spawn ( { type : 'js' , initOptions : { bits : 512 } } , cb )
78118 ] , ( err , n ) => {
79119 expect ( err ) . to . not . exist ( )
80120 nodes = n
81121 goDaemon = nodes [ 0 ]
82- jsDaemon = nodes [ 1 ]
83- js2Daemon = nodes [ 2 ]
122+ goDaemon2 = nodes [ 1 ]
123+ jsDaemon = nodes [ 2 ]
124+ jsDaemon2 = nodes [ 3 ]
84125 done ( )
85126 } )
86127 } )
@@ -121,7 +162,37 @@ describe.skip('exchange files', () => {
121162 ] , done )
122163 } )
123164
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 ) {
125196 this . timeout ( timeout )
126197
127198 let jsId
@@ -130,17 +201,17 @@ describe.skip('exchange files', () => {
130201 series ( [
131202 ( cb ) => parallel ( [
132203 ( cb ) => jsDaemon . api . id ( cb ) ,
133- ( cb ) => js2Daemon . api . id ( cb )
204+ ( cb ) => jsDaemon2 . api . id ( cb )
134205 ] , ( err , ids ) => {
135206 expect ( err ) . to . not . exist ( )
136207 jsId = ids [ 0 ]
137208 js2Id = ids [ 1 ]
138209 cb ( )
139210 } ) ,
140- ( cb ) => js2Daemon . api . swarm . connect ( jsId . addresses [ 0 ] , cb ) ,
211+ ( cb ) => jsDaemon2 . api . swarm . connect ( jsId . addresses [ 0 ] , cb ) ,
141212 ( cb ) => jsDaemon . api . swarm . connect ( js2Id . addresses [ 0 ] , cb ) ,
142213 ( cb ) => parallel ( [
143- ( cb ) => js2Daemon . api . swarm . peers ( cb ) ,
214+ ( cb ) => jsDaemon2 . api . swarm . peers ( cb ) ,
144215 ( cb ) => jsDaemon . api . swarm . peers ( cb )
145216 ] , ( err , peers ) => {
146217 expect ( err ) . to . not . exist ( )
@@ -162,7 +233,7 @@ describe.skip('exchange files', () => {
162233 ( res , cb ) => jsDaemon . api . cat ( res [ 0 ] . hash , cb )
163234 ] , ( err , file ) => {
164235 expect ( err ) . to . not . exist ( )
165- expect ( file ) . to . be . eql ( data )
236+ expect ( file ) . to . eql ( data )
166237 done ( )
167238 } )
168239 } )
@@ -177,85 +248,120 @@ describe.skip('exchange files', () => {
177248 ( res , cb ) => goDaemon . api . cat ( res [ 0 ] . hash , cb )
178249 ] , ( err , file ) => {
179250 expect ( err ) . to . not . exist ( )
180- expect ( file ) . to . be . eql ( data )
251+ expect ( file ) . to . eql ( data )
181252 done ( )
182253 } )
183254 } )
184255
185- it ( `js -> js : ${ pretty ( size ) } ` , function ( done ) {
256+ it ( `js -> js2 : ${ pretty ( size ) } ` , function ( done ) {
186257 this . timeout ( timeout )
187258
188259 const data = crypto . randomBytes ( size )
189260
190261 waterfall ( [
191- ( cb ) => js2Daemon . api . add ( data , cb ) ,
262+ ( cb ) => jsDaemon2 . api . add ( data , cb ) ,
192263 ( res , cb ) => jsDaemon . api . cat ( res [ 0 ] . hash , cb )
193264 ] , ( err , file ) => {
194265 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 )
196282 done ( )
197283 } )
198284 } )
199285 } ) )
200286
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 ( ) {
204292 this . timeout ( timeout )
205293
206294 const dir = tmpDir ( )
207-
208295 return randomFs ( {
209296 path : dir ,
210- depth : 5 ,
297+ depth : d ,
211298 number : num
212299 } ) . then ( ( ) => {
213300 return goDaemon . api . util . addFromFs ( dir , { recursive : true } )
214301 } ) . then ( ( res ) => {
215302 const hash = res [ res . length - 1 ] . hash
216- return jsDaemon . api . object . get ( hash )
303+ return jsDaemon . api . files . get ( hash )
217304 } ) . then ( ( res ) => {
218305 expect ( res ) . to . exist ( )
219306 return rmDir ( dir )
220307 } )
221308 } )
222309
223- it ( `js -> go: depth: 5 , num: ${ num } ` , function ( ) {
310+ it ( `js -> go: depth: ${ d } , num: ${ num } ` , function ( ) {
224311 this . timeout ( timeout )
225312
226313 const dir = tmpDir ( )
227314 return randomFs ( {
228315 path : dir ,
229- depth : 5 ,
316+ depth : d ,
230317 number : num
231318 } ) . then ( ( ) => {
232319 return jsDaemon . api . util . addFromFs ( dir , { recursive : true } )
233320 } ) . then ( ( res ) => {
234321 const hash = res [ res . length - 1 ] . hash
235- return goDaemon . api . object . get ( hash )
322+ return goDaemon . api . files . get ( hash )
236323 } ) . then ( ( res ) => {
237324 expect ( res ) . to . exist ( )
238325 return rmDir ( dir )
239326 } )
240327 } )
241328
242- it ( `js -> js : depth: 5 , num: ${ num } ` , function ( ) {
329+ it ( `js -> js2 : depth: ${ d } , num: ${ num } ` , function ( ) {
243330 this . timeout ( timeout )
244331
245332 const dir = tmpDir ( )
246333 return randomFs ( {
247334 path : dir ,
248- depth : 5 ,
335+ depth : d ,
249336 number : num
250337 } ) . then ( ( ) => {
251- return js2Daemon . api . util . addFromFs ( dir , { recursive : true } )
338+ return jsDaemon2 . api . util . addFromFs ( dir , { recursive : true } )
252339 } ) . then ( ( res ) => {
253340 const hash = res [ res . length - 1 ] . hash
254- return jsDaemon . api . object . get ( hash )
341+ return jsDaemon . api . files . get ( hash )
255342 } ) . then ( ( res ) => {
256343 expect ( res ) . to . exist ( )
257344 return rmDir ( dir )
258345 } )
259346 } )
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+ } ) ) )
261367} )
0 commit comments