33
44const multihashing = require ( 'multihashing-async' )
55const waterfall = require ( 'async/waterfall' )
6+ const parallel = require ( 'async/parallel' )
67const CID = require ( 'cids' )
78const { spawnNodesWithId } = require ( '../utils/spawn' )
89const { getDescribe, getIt, expect } = require ( '../utils/mocha' )
@@ -26,6 +27,7 @@ module.exports = (createCommon, options) => {
2627 describe ( '.dht.findProvs' , function ( ) {
2728 let nodeA
2829 let nodeB
30+ let nodeC
2931
3032 before ( function ( done ) {
3133 // CI takes longer to instantiate the daemon, so we need to increase the
@@ -35,35 +37,54 @@ module.exports = (createCommon, options) => {
3537 common . setup ( ( err , factory ) => {
3638 expect ( err ) . to . not . exist ( )
3739
38- spawnNodesWithId ( 2 , factory , ( err , nodes ) => {
40+ spawnNodesWithId ( 3 , factory , ( err , nodes ) => {
3941 expect ( err ) . to . not . exist ( )
4042
4143 nodeA = nodes [ 0 ]
4244 nodeB = nodes [ 1 ]
45+ nodeC = nodes [ 2 ]
4346
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 )
4551 } )
4652 } )
4753 } )
4854
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+
4971 after ( function ( done ) {
5072 this . timeout ( 50 * 1000 )
5173
5274 common . teardown ( done )
5375 } )
5476
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 )
5779
5880 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 ) ,
6482 ( 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+ ] )
6788 cb ( )
6889 }
6990 ] , done )
0 commit comments