Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Commit

Permalink
chore: more test stabilization (#1541)
Browse files Browse the repository at this point in the history
* chore: increase preload test timeouts

Also reduces the umber of bits for the Peer ID generated in bitswap CLI tests.

License: MIT
Signed-off-by: Alan Shaw <alan@tableflip.io>

* feat: adds waitFor utility

Calls back when async func returns true.

License: MIT
Signed-off-by: Alan Shaw <alan@tableflip.io>

* fix: appease the linter

License: MIT
Signed-off-by: Alan Shaw <alan@tableflip.io>

* fix: appease linter more

License: MIT
Signed-off-by: Alan Shaw <alan@tableflip.io>

* chore: increase pin after hook timeout

License: MIT
Signed-off-by: Alan Shaw <alan@tableflip.io>

* chore: increase default test timeout to 10s

License: MIT
Signed-off-by: Alan Shaw <alan@tableflip.io>

* chore: cleanup temp repos after tests

License: MIT
Signed-off-by: Alan Shaw <alan@tableflip.io>

* chore: remove .only

License: MIT
Signed-off-by: Alan Shaw <alan@tableflip.io>

* chore: appease linter

License: MIT
Signed-off-by: Alan Shaw <alan@tableflip.io>

* chore: ten seconds is the new default timeout

License: MIT
Signed-off-by: Alan Shaw <alan@tableflip.io>

* fix: repo in test

License: MIT
Signed-off-by: Alan Shaw <alan@tableflip.io>
  • Loading branch information
alanshaw committed Sep 7, 2018
1 parent bf72f3a commit db703b9
Show file tree
Hide file tree
Showing 15 changed files with 192 additions and 85 deletions.
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@
"scripts": {
"lint": "aegir lint",
"build": "aegir build",
"test": "aegir test -t node -t browser -t webworker --no-cors",
"test:node": "aegir test -t node",
"test:browser": "aegir test -t browser --no-cors",
"test:webworker": "aegir test -t webworker --no-cors",
"test:node:core": "aegir test -t node -f test/core/**/*.js",
"test:node:http": "aegir test -t node -f test/http-api/index.js",
"test:node:gateway": "aegir test -t node -f test/gateway/index.js",
"test:node:cli": "aegir test -t node -f test/cli/index.js",
"test:bootstrapers": "IPFS_TEST=bootstrapers aegir test -t browser -f test/bootstrapers.js",
"test": "aegir test -t node -t browser -t webworker --no-cors --timeout=10000",
"test:node": "aegir test -t node --timeout=10000",
"test:browser": "aegir test -t browser --no-cors --timeout=10000",
"test:webworker": "aegir test -t webworker --no-cors --timeout=10000",
"test:node:core": "aegir test -t node -f test/core/**/*.js --timeout=10000",
"test:node:http": "aegir test -t node -f test/http-api/index.js --timeout=10000",
"test:node:gateway": "aegir test -t node -f test/gateway/index.js --timeout=10000",
"test:node:cli": "aegir test -t node -f test/cli/index.js --timeout=10000",
"test:bootstrapers": "IPFS_TEST=bootstrapers aegir test -t browser -f test/bootstrapers.js --timeout=10000",
"benchmark": "echo \"Error: no benchmarks yet\" && exit 1",
"benchmark:node": "echo \"Error: no benchmarks yet\" && exit 1",
"benchmark:node:core": "echo \"Error: no benchmarks yet\" && exit 1",
Expand Down
44 changes: 29 additions & 15 deletions test/bootstrapers.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,40 +6,54 @@ const dirtyChai = require('dirty-chai')
const expect = chai.expect
chai.use(dirtyChai)
const IPFS = require('..')
const list = require('../src/core/runtime/config-browser.js')().Bootstrap
const IPFSFactory = require('ipfsd-ctl')
const bootstrapList = require('../src/core/runtime/config-browser.js')().Bootstrap
const waitFor = require('./utils/wait-for')

/*
* These tests were graciously made for lgierth, so that he can test the
* WebSockets Bootstrappers easily <3
*/
describe('Check that a js-ipfs node can indeed contact the bootstrappers', function () {
this.timeout(60 * 1000)
describe('Check that a js-ipfs node can indeed contact the bootstrappers', () => {
let ipfsd

it('a node connects to bootstrapers', (done) => {
const node = new IPFS({
before(function (done) {
this.timeout(30 * 1000)

const factory = IPFSFactory.create({ type: 'proc', exec: IPFS })

factory.spawn({
config: {
Addresses: {
Swarm: []
}
}
}, (err, node) => {
expect(err).to.not.exist()
ipfsd = node
done()
})
})

node.on('ready', check)
after(done => ipfsd.stop(done))

function check () {
node.swarm.peers((err, peers) => {
expect(err).to.not.exist()
it('a node connects to bootstrappers', function (done) {
this.timeout(2 * 60 * 1000)

if (peers.length !== list.length) {
return setTimeout(check, 2000)
}
const test = (cb) => {
ipfsd.api.swarm.peers((err, peers) => {
if (err) return cb(err)

const peerList = peers.map((peer) => peer.addr.toString())
expect(peers.length).to.equal(list.length)
expect(peerList).to.eql(list)

node.stop(done)
if (peerList.length !== bootstrapList.length) {
return cb(null, false)
}

cb(null, bootstrapList.every(addr => peerList.includes(addr)))
})
}

waitFor(test, { name: 'connect to all bootstrap nodes', timeout: 60 * 1000 }, done)
})
})
31 changes: 26 additions & 5 deletions test/cli/bitswap.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,46 @@
const expect = require('chai').expect
const runOn = require('../utils/on-and-off').on
const PeerId = require('peer-id')
const waitFor = require('../utils/wait-for')

describe('bitswap', () => runOn((thing) => {
let ipfs
let peerId
const key = 'QmUBdnXXPyoDFXj3Hj39dNJ5VkN3QFRskXxcGaYFBB8CNR'

before(() => {
ipfs = thing.ipfs
})

before(() => {
ipfs('block get ' + key).catch(() => {})
})

before(function (done) {
this.timeout(60 * 1000)
ipfs = thing.ipfs
ipfs('block get ' + key)
.then(() => {})
.catch(() => {})
PeerId.create((err, peer) => {

PeerId.create({ bits: 512 }, (err, peer) => {
expect(err).to.not.exist()
peerId = peer.toB58String()
done()
})
})

before(function (done) {
this.timeout(2 * 60 * 1000)

const test = (cb) => {
ipfs('bitswap wantlist')
.then(out => cb(null, out.includes(key)))
.catch(cb)
}

waitFor(test, {
name: key + ' to be wanted',
timeout: 60 * 1000
}, done)
})

it('wantlist', function () {
this.timeout(20 * 1000)
return ipfs('bitswap wantlist').then((out) => {
Expand Down
3 changes: 1 addition & 2 deletions test/cli/pin.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ describe('pin', () => runOnAndOff(thing => {
})

describe('rm', function () {
it('recursively (default)', function () {
this.timeout(10 * 1000)
it('recursively (default)', () => {
return ipfs(`pin rm ${pins.root}`)
.then(out => expect(out).to.equal(`unpinned ${pins.root}\n`))
})
Expand Down
8 changes: 2 additions & 6 deletions test/cli/resolve.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ describe('resolve', () => runOnAndOff((thing) => {
ipfs = thing.ipfs
})

it('should resolve an IPFS hash', function () {
this.timeout(10 * 1000)

it('should resolve an IPFS hash', () => {
const filePath = path.join(process.cwd(), '/src/init-files/init-docs/readme')
let hash

Expand All @@ -31,9 +29,7 @@ describe('resolve', () => runOnAndOff((thing) => {
})
})

it('should resolve an IPFS path link', function () {
this.timeout(10 * 1000)

it('should resolve an IPFS path link', () => {
const filePath = path.join(process.cwd(), '/src/init-files/init-docs/readme')
let fileHash, rootHash

Expand Down
58 changes: 41 additions & 17 deletions test/core/create-node.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ const IPFS = require('../../src/core')
const createTempRepo = require('../utils/create-repo-nodejs.js')

describe('create node', function () {
let tempRepo

beforeEach(() => {
tempRepo = createTempRepo()
})

afterEach((done) => tempRepo.teardown(done))

it('custom repoPath', function (done) {
this.timeout(80 * 1000)

Expand Down Expand Up @@ -49,7 +57,7 @@ describe('create node', function () {
this.timeout(80 * 1000)

const node = new IPFS({
repo: createTempRepo(),
repo: tempRepo,
config: {
Addresses: {
Swarm: []
Expand All @@ -73,7 +81,7 @@ describe('create node', function () {
this.timeout(80 * 1000)

const node = IPFS.createNode({
repo: createTempRepo(),
repo: tempRepo,
config: {
Addresses: {
Swarm: []
Expand All @@ -100,7 +108,7 @@ describe('create node', function () {
this.timeout(80 * 1000)

const node = new IPFS({
repo: createTempRepo(),
repo: tempRepo,
init: {
bits: 512
},
Expand All @@ -127,7 +135,7 @@ describe('create node', function () {
this.timeout(80 * 1000)

const node = new IPFS({
repo: createTempRepo(),
repo: tempRepo,
init: false,
config: {
Addresses: {
Expand Down Expand Up @@ -159,7 +167,7 @@ describe('create node', function () {
this.timeout(80 * 1000)

const node = new IPFS({
repo: createTempRepo(),
repo: tempRepo,
init: false,
start: false,
config: {
Expand Down Expand Up @@ -189,7 +197,7 @@ describe('create node', function () {
this.timeout(80 * 1000)

const node = new IPFS({
repo: createTempRepo(),
repo: tempRepo,
init: true,
start: false,
config: {
Expand All @@ -211,7 +219,7 @@ describe('create node', function () {
this.timeout(80 * 1000)

const node = new IPFS({
repo: createTempRepo(),
repo: tempRepo,
init: true,
start: false,
config: {
Expand All @@ -232,7 +240,7 @@ describe('create node', function () {
if (!isNode) { return done() }

const node = new IPFS({
repo: createTempRepo(),
repo: tempRepo,
config: {
Addresses: {
Swarm: ['/ip4/127.0.0.1/tcp/9977']
Expand All @@ -258,7 +266,7 @@ describe('create node', function () {
this.timeout(80 * 1000)

const node = new IPFS({
repo: createTempRepo(),
repo: tempRepo,
config: {
Addresses: {
Swarm: []
Expand All @@ -279,7 +287,7 @@ describe('create node', function () {
this.timeout(80 * 1000)

const node = new IPFS({
repo: createTempRepo(),
repo: tempRepo,
config: {
Addresses: {
Swarm: []
Expand All @@ -299,7 +307,7 @@ describe('create node', function () {
this.timeout(80 * 1000)

const options = {
repo: createTempRepo(),
repo: tempRepo,
config: {
Addresses: {
Swarm: []
Expand All @@ -323,13 +331,13 @@ describe('create node', function () {
})

it('does not share identity with a simultaneously created node', function (done) {
this.timeout(80 * 1000)
this.timeout(2 * 60 * 1000)

let _nodeNumber = 0
function createNode () {
function createNode (repo) {
_nodeNumber++
return new IPFS({
repo: createTempRepo(),
repo,
init: { emptyRepo: true },
config: {
Addresses: {
Expand All @@ -344,10 +352,19 @@ describe('create node', function () {
})
}

const nodeA = createNode()
const nodeB = createNode()
let repoA
let repoB
let nodeA
let nodeB

waterfall([
(cb) => {
repoA = createTempRepo()
repoB = createTempRepo()
nodeA = createNode(repoA)
nodeB = createNode(repoB)
cb()
},
(cb) => parallel([
(cb) => nodeA.once('start', cb),
(cb) => nodeB.once('start', cb)
Expand All @@ -364,7 +381,14 @@ describe('create node', function () {
parallel([
(cb) => nodeA.stop(cb),
(cb) => nodeB.stop(cb)
], (stopError) => done(error || stopError))
], (stopError) => {
parallel([
(cb) => repoA.teardown(cb),
(cb) => repoB.teardown(cb)
], (teardownError) => {
done(error || stopError || teardownError)
})
})
})
})
})
4 changes: 1 addition & 3 deletions test/core/init.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,7 @@ describe('init', () => {
})
})

it('pregenerated key is being used', function (done) {
this.timeout(10 * 1000)

it('pregenerated key is being used', (done) => {
ipfs.init({ privateKey }, (err) => {
expect(err).to.not.exist()

Expand Down
4 changes: 1 addition & 3 deletions test/core/kad-dht.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,7 @@ describe.skip('verify that kad-dht is doing its thing', () => {

after((done) => parallel(nodes.map((node) => (cb) => node.stop(cb)), done))

it.skip('add a file in C, fetch through B in A', function (done) {
this.timeout(10 * 1000)

it.skip('add a file in C, fetch through B in A', (done) => {
const file = {
path: 'testfile.txt',
content: Buffer.from('hello kad')
Expand Down
2 changes: 2 additions & 0 deletions test/core/key-exchange.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ describe('key exchange', () => {

after((done) => ipfs.stop(done))

after((done) => repo.teardown(done))

it('exports', (done) => {
ipfs.key.export('self', passwordPem, (err, pem) => {
expect(err).to.not.exist()
Expand Down
2 changes: 2 additions & 0 deletions test/core/pin-set.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ describe('pinSet', function () {
ipfs.stop(done)
})

after((done) => repo.teardown(done))

describe('storeItems', function () {
it('generates a root node with links and hash', function (done) {
const expectedRootHash = 'QmcLiSTjcjoVC2iuGbk6A2PVcWV3WvjZT4jxfNis1vjyrR'
Expand Down
Loading

0 comments on commit db703b9

Please sign in to comment.