3
3
4
4
const multihashing = require ( 'multihashing-async' )
5
5
const waterfall = require ( 'async/waterfall' )
6
+ const parallel = require ( 'async/parallel' )
6
7
const CID = require ( 'cids' )
7
8
const { spawnNodesWithId } = require ( '../utils/spawn' )
8
9
const { getDescribe, getIt, expect } = require ( '../utils/mocha' )
@@ -26,6 +27,7 @@ module.exports = (createCommon, options) => {
26
27
describe ( '.dht.findProvs' , function ( ) {
27
28
let nodeA
28
29
let nodeB
30
+ let nodeC
29
31
30
32
before ( function ( done ) {
31
33
// CI takes longer to instantiate the daemon, so we need to increase the
@@ -35,35 +37,54 @@ module.exports = (createCommon, options) => {
35
37
common . setup ( ( err , factory ) => {
36
38
expect ( err ) . to . not . exist ( )
37
39
38
- spawnNodesWithId ( 2 , factory , ( err , nodes ) => {
40
+ spawnNodesWithId ( 3 , factory , ( err , nodes ) => {
39
41
expect ( err ) . to . not . exist ( )
40
42
41
43
nodeA = nodes [ 0 ]
42
44
nodeB = nodes [ 1 ]
45
+ nodeC = nodes [ 2 ]
43
46
44
- connect ( nodeB , nodeA . peerId . addresses [ 0 ] , done )
47
+ parallel ( [
48
+ ( cb ) => connect ( nodeB , nodeA . peerId . addresses [ 0 ] , cb ) ,
49
+ ( cb ) => connect ( nodeC , nodeB . peerId . addresses [ 0 ] , cb )
50
+ ] , done )
45
51
} )
46
52
} )
47
53
} )
48
54
55
+ let providedCid
56
+ before ( 'add providers for the same cid' , function ( done ) {
57
+ this . timeout ( 10 * 1000 )
58
+ parallel ( [
59
+ ( cb ) => nodeB . object . new ( 'unixfs-dir' , cb ) ,
60
+ ( cb ) => nodeC . object . new ( 'unixfs-dir' , cb )
61
+ ] , ( err , cids ) => {
62
+ if ( err ) return done ( err )
63
+ providedCid = cids [ 0 ]
64
+ parallel ( [
65
+ ( cb ) => nodeB . dht . provide ( providedCid , cb ) ,
66
+ ( cb ) => nodeC . dht . provide ( providedCid , cb )
67
+ ] , done )
68
+ } )
69
+ } )
70
+
49
71
after ( function ( done ) {
50
72
this . timeout ( 50 * 1000 )
51
73
52
74
common . teardown ( done )
53
75
} )
54
76
55
- it ( 'should provide from one node and find it through another node ' , function ( done ) {
56
- this . timeout ( 80 * 1000 )
77
+ it ( 'should be able to find providers ' , function ( done ) {
78
+ this . timeout ( 20 * 1000 )
57
79
58
80
waterfall ( [
59
- ( cb ) => nodeB . object . new ( 'unixfs-dir' , cb ) ,
60
- ( cid , cb ) => {
61
- nodeB . dht . provide ( cid , ( err ) => cb ( err , cid ) )
62
- } ,
63
- ( cid , cb ) => nodeA . dht . findProvs ( cid , cb ) ,
81
+ ( cb ) => nodeA . dht . findProvs ( providedCid , cb ) ,
64
82
( provs , cb ) => {
65
- expect ( provs . map ( ( p ) => p . id . toB58String ( ) ) )
66
- . to . eql ( [ nodeB . peerId . id ] )
83
+ const providerIds = provs . map ( ( p ) => p . id . toB58String ( ) )
84
+ expect ( providerIds ) . to . have . members ( [
85
+ nodeB . peerId . id ,
86
+ nodeC . peerId . id
87
+ ] )
67
88
cb ( )
68
89
}
69
90
] , done )
0 commit comments