Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test: clean up bitswap tests
  • Loading branch information
daviddias committed Nov 8, 2017
commit c7fd99a83915647644b3a2f05367b58db5c1a30f
83 changes: 40 additions & 43 deletions test/core/bitswap.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,61 +24,55 @@ const createTempRepo = require('../utils/create-repo-nodejs.js')

const IPFS = require('../../src/core')

function makeBlock (cb) {
function makeBlock (callback) {
const d = Buffer.from(`IPFS is awesome ${Math.random()}`)

multihashing(d, 'sha2-256', (err, multihash) => {
if (err) {
return cb(err)
return callback(err)
}
cb(null, new Block(d, new CID(multihash)))
callback(null, new Block(d, new CID(multihash)))
})
}

describe('bitswap', () => {
let inProcNode // Node spawned inside this process

beforeEach(function (done) {
this.timeout(20 * 1000)
const repo = createTempRepo()
this.timeout(10 * 1000)

let config = {
repo: createTempRepo(),
config: {
Addresses: {
Swarm: []
},
Discovery: {
MDNS: {
Enabled: false
}
},
Bootstrap: []
}
}

if (!isNode) {
inProcNode = new IPFS({
repo: repo,
config: {
Addresses: {
Swarm: []
},
Discovery: {
MDNS: {
Enabled: false
}
},
Bootstrap: []
}
})
} else {
inProcNode = new IPFS({
repo: repo,
if (isNode) {
config = Object.assign(config, {
config: {
Addresses: {
Swarm: ['/ip4/127.0.0.1/tcp/0']
},
Discovery: {
MDNS: {
Enabled: false
}
},
Bootstrap: []
}
}
})
}

inProcNode = new IPFS(config)
inProcNode.on('start', () => done())
})

afterEach(function (done) {
this.timeout(20 * 1000)
this.timeout(10 * 1000)

inProcNode.stop(() => done())
})

Expand Down Expand Up @@ -106,11 +100,9 @@ describe('bitswap', () => {
function connectNodes (remoteNode, ipn, done) {
series([
(cb) => wire(remoteNode, ipn, cb),
(cb) => setTimeout(() => {
// need timeout so we wait for identify to happen.
// This call is just to ensure identify happened
wire(ipn, remoteNode, cb)
}, 300)
// need timeout so we wait for identify to happen.
// This call is just to ensure identify happened
(cb) => setTimeout(() => wire(ipn, remoteNode, cb), 300)
], done)
}

Expand All @@ -124,7 +116,9 @@ describe('bitswap', () => {
}

describe('fetches a remote block', () => {
it('2 peers', (done) => {
it('2 peers', function (done) {
this.timeout(10 * 1000)

let remoteNode
let block
waterfall([
Expand All @@ -140,13 +134,15 @@ describe('bitswap', () => {
(cb) => remoteNode.block.put(block, cb),
(key, cb) => inProcNode.block.get(block.cid, cb),
(b, cb) => {
expect(b.data).to.be.eql(block.data)
expect(b.data).to.eql(block.data)
cb()
}
], done)
}).timeout(20 * 1000)
})

it('3 peers', function (done) {
this.timeout(20 * 1000)

it('3 peers', (done) => {
let blocks
const remoteNodes = []

Expand Down Expand Up @@ -188,8 +184,8 @@ describe('bitswap', () => {
], cbI)
}), cb)
], done)
}).timeout(20 * 1000)
}).timeout(60 * 1000)
})
})

describe('fetches a remote file', () => {
it('2 peers', (done) => {
Expand Down Expand Up @@ -223,7 +219,8 @@ describe('bitswap', () => {
let node

before(function (done) {
this.timeout(20 * 1000)
this.timeout(10 * 1000)

node = new IPFS({
repo: createTempRepo(),
start: false,
Expand Down