diff --git a/package.json b/package.json index 1ef3ba462a..575661b419 100644 --- a/package.json +++ b/package.json @@ -75,7 +75,7 @@ "expose-loader": "^0.7.4", "form-data": "^2.3.1", "hat": "0.0.3", - "interface-ipfs-core": "~0.36.8", + "interface-ipfs-core": "~0.36.11", "ipfsd-ctl": "~0.25.1", "left-pad": "^1.2.0", "lodash": "^4.17.4", diff --git a/test/cli/files.js b/test/cli/files.js index 5c57c7d208..4a8eb70efe 100644 --- a/test/cli/files.js +++ b/test/cli/files.js @@ -107,7 +107,7 @@ describe('files', () => runOnAndOff((thing) => { }) it('add with progress', function () { - this.timeout(20 * 1000) + this.timeout(30 * 1000) return ipfs('files add -p src/init-files/init-docs/readme') .then((out) => { @@ -117,7 +117,7 @@ describe('files', () => runOnAndOff((thing) => { }) it('add', function () { - this.timeout(20 * 1000) + this.timeout(30 * 1000) return ipfs('files add src/init-files/init-docs/readme') .then((out) => { @@ -127,7 +127,7 @@ describe('files', () => runOnAndOff((thing) => { }) it('add alias', function () { - this.timeout(20 * 1000) + this.timeout(30 * 1000) return ipfs('add src/init-files/init-docs/readme') .then((out) => { @@ -137,7 +137,7 @@ describe('files', () => runOnAndOff((thing) => { }) it('add recursively test', function () { - this.timeout(20 * 1000) + this.timeout(60 * 1000) return ipfs('files add -r test/fixtures/test-data/recursive-get-dir') .then((out) => { @@ -146,7 +146,7 @@ describe('files', () => runOnAndOff((thing) => { }) it('add directory with trailing slash test', function () { - this.timeout(20 * 1000) + this.timeout(30 * 1000) return ipfs('files add -r test/fixtures/test-data/recursive-get-dir/') .then((out) => { @@ -155,7 +155,7 @@ describe('files', () => runOnAndOff((thing) => { }) it('add and wrap with a directory', function () { - this.timeout(20 * 1000) + this.timeout(30 * 1000) return ipfs('add -w src/init-files/init-docs/readme').then((out) => { expect(out).to.be.eql([ @@ -166,7 +166,7 @@ describe('files', () => runOnAndOff((thing) => { }) it('add with cid-version=0', function () { - this.timeout(20 * 1000) + this.timeout(30 * 1000) return ipfs('add src/init-files/init-docs/readme --cid-version=0').then((out) => { expect(out) @@ -184,7 +184,7 @@ describe('files', () => runOnAndOff((thing) => { // // This retains feature parity without having to implement raw-leaves. it('add with cid-version=1', function () { - this.timeout(20 * 1000) + this.timeout(30 * 1000) return new Promise((resolve, reject) => { ipfs('add src/init-files/init-docs/readme --cid-version=1') @@ -214,7 +214,7 @@ describe('files', () => runOnAndOff((thing) => { // // This retains feature parity without having to implement raw-leaves. it('add with cid-version=1 and raw-leaves=true', function () { - this.timeout(20 * 1000) + this.timeout(30 * 1000) return new Promise((resolve, reject) => { ipfs('add src/init-files/init-docs/readme --cid-version=1 --raw-leaves=true') @@ -227,7 +227,7 @@ describe('files', () => runOnAndOff((thing) => { }) it('add --quiet', function () { - this.timeout(20 * 1000) + this.timeout(30 * 1000) return ipfs('files add -q src/init-files/init-docs/readme') .then((out) => { @@ -237,7 +237,7 @@ describe('files', () => runOnAndOff((thing) => { }) it('add --quieter', function () { - this.timeout(20 * 1000) + this.timeout(30 * 1000) return ipfs('files add -Q -w test/fixtures/test-data/hello test/test-data/node.json') .then((out) => { @@ -247,7 +247,7 @@ describe('files', () => runOnAndOff((thing) => { }) it('add --silent', function () { - this.timeout(20 * 1000) + this.timeout(30 * 1000) return ipfs('files add --silent src/init-files/init-docs/readme') .then((out) => { @@ -257,7 +257,7 @@ describe('files', () => runOnAndOff((thing) => { }) it('cat', function () { - this.timeout(20 * 1000) + this.timeout(30 * 1000) return ipfs('files cat QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB') .then((out) => { diff --git a/test/cli/id.js b/test/cli/id.js index 6071a7e427..1ceeb1843d 100644 --- a/test/cli/id.js +++ b/test/cli/id.js @@ -8,12 +8,12 @@ describe('id', () => runOnAndOff((thing) => { let ipfs before(function () { - this.timeout(40 * 1000) + this.timeout(60 * 1000) ipfs = thing.ipfs }) it('get the id', function () { - this.timeout(40 * 1000) + this.timeout(60 * 1000) return ipfs('id').then((res) => { const id = JSON.parse(res) diff --git a/test/cli/pubsub.js b/test/cli/pubsub.js index d4fad22c93..3df5bf8417 100644 --- a/test/cli/pubsub.js +++ b/test/cli/pubsub.js @@ -26,7 +26,7 @@ describe('pubsub', function () { const topicC = 'nonscentsC' before(function (done) { - this.timeout(40 * 1000) + this.timeout(60 * 1000) instanceFactory = new InstanceFactory() instanceFactory.spawnNode((err, _node) => { @@ -73,7 +73,7 @@ describe('pubsub', function () { }) it('ls', function () { - this.timeout(40 * 1000) + this.timeout(80 * 1000) const sub = cli(`pubsub sub ${topicB}`) @@ -108,32 +108,31 @@ describe('pubsub', function () { }) } - series( - [ - (cb) => httpApi.id((err, peerInfo) => { - expect(err).to.not.exist() - peerAddress = peerInfo.addresses[0] - expect(peerAddress).to.exist() - cb() - }), - (cb) => node.id((err, peerInfo) => { - expect(err).to.not.exist() - instancePeerId = peerInfo.id.toString() - cb() - }), - (cb) => node.swarm.connect(peerAddress, cb), - (cb) => node.pubsub.subscribe(topicC, handler, cb) - ], - (err) => { + series([ + (cb) => httpApi.id((err, peerInfo) => { expect(err).to.not.exist() - sub = cli(`pubsub sub ${topicC}`) - - return Promise.all([ - sub.catch(ignoreKill), - delay(1000) - .then(() => cli(`pubsub pub ${topicC} world`)) - ]) - }) + peerAddress = peerInfo.addresses[0] + expect(peerAddress).to.exist() + cb() + }), + (cb) => node.id((err, peerInfo) => { + expect(err).to.not.exist() + instancePeerId = peerInfo.id.toString() + cb() + }), + (cb) => node.swarm.connect(peerAddress, cb), + (cb) => node.pubsub.subscribe(topicC, handler, cb) + ], + (err) => { + expect(err).to.not.exist() + sub = cli(`pubsub sub ${topicC}`) + + return Promise.all([ + sub.catch(ignoreKill), + delay(1000) + .then(() => cli(`pubsub pub ${topicC} world`)) + ]) + }) }) }) diff --git a/test/cli/swarm.js b/test/cli/swarm.js index 46dff8881d..d2c69846be 100644 --- a/test/cli/swarm.js +++ b/test/cli/swarm.js @@ -18,7 +18,7 @@ describe('swarm', () => { before(function (done) { // CI takes longer to instantiate the daemon, so we need to increase the // timeout for the before step - this.timeout(60 * 1000) + this.timeout(80 * 1000) factory = new Factory() @@ -46,7 +46,7 @@ describe('swarm', () => { after((done) => factory.dismantle(done)) describe('daemon on (through http-api)', function () { - this.timeout(40 * 1000) + this.timeout(60 * 1000) it('connect', () => { return ipfsA('swarm', 'connect', bMultiaddr).then((out) => { diff --git a/test/core/bitswap.spec.js b/test/core/bitswap.spec.js index 007a77ec36..f9ebe844fe 100644 --- a/test/core/bitswap.spec.js +++ b/test/core/bitswap.spec.js @@ -34,6 +34,44 @@ function makeBlock (callback) { }) } +function wire (targetNode, dialerNode, callback) { + targetNode.id((err, identity) => { + expect(err).to.not.exist() + const addr = identity.addresses + .map((addr) => multiaddr(addr.toString().split('ipfs')[0])) + .filter((addr) => _.includes(addr.protoNames(), 'ws'))[0] + + if (!addr) { + // Note: the browser doesn't have a websockets listening addr + return callback() + } + + const targetAddr = addr + .encapsulate(multiaddr(`/ipfs/${identity.id}`)).toString() + .replace('0.0.0.0', '127.0.0.1') + + dialerNode.swarm.connect(targetAddr, callback) + }) +} + +function connectNodes (remoteNode, inProcNode, callback) { + series([ + (cb) => wire(remoteNode, inProcNode, cb), + // need timeout so we wait for identify to happen. + // This call is just to ensure identify happened + (cb) => setTimeout(() => wire(inProcNode, remoteNode, cb), 500) + ], callback) +} + +function addNode (num, inProcNode, callback) { + num = leftPad(num, 3, 0) + + const apiUrl = `/ip4/127.0.0.1/tcp/31${num}` + const remoteNode = new API(apiUrl) + + connectNodes(remoteNode, inProcNode, (err) => callback(err, remoteNode)) +} + describe('bitswap', function () { this.timeout(80 * 1000) @@ -42,7 +80,7 @@ describe('bitswap', function () { beforeEach(function (done) { this.timeout(60 * 1000) - let config = { + let options = { repo: createTempRepo(), config: { Addresses: { @@ -58,7 +96,7 @@ describe('bitswap', function () { } if (isNode) { - config = Object.assign(config, { + options = Object.assign(options, { config: { Addresses: { Swarm: ['/ip4/127.0.0.1/tcp/0'] @@ -67,150 +105,110 @@ describe('bitswap', function () { }) } - inProcNode = new IPFS(config) - inProcNode.on('start', () => done()) + inProcNode = new IPFS(options) + inProcNode.on('ready', () => done()) }) afterEach(function (done) { - this.timeout(30 * 1000) - + this.timeout(60 * 1000) inProcNode.stop(() => done()) }) - describe('connections', () => { - function wire (targetNode, dialerNode, done) { - targetNode.id((err, identity) => { - expect(err).to.not.exist() - const addr = identity.addresses - .map((addr) => multiaddr(addr.toString().split('ipfs')[0])) - .filter((addr) => _.includes(addr.protoNames(), 'ws'))[0] + describe('transfer a block between', () => { + it('2 peers', function (done) { + this.timeout(40 * 1000) - if (!addr) { - // Note: the browser doesn't have a websockets listening addr - return done() + let remoteNode + let block + waterfall([ + (cb) => parallel([ + (cb) => makeBlock(cb), + (cb) => addNode(13, inProcNode, cb) + ], cb), + (res, cb) => { + block = res[0] + remoteNode = res[1] + cb() + }, + (cb) => remoteNode.block.put(block, cb), + (key, cb) => inProcNode.block.get(block.cid, cb), + (b, cb) => { + expect(b.data).to.eql(block.data) + cb() } - - const targetAddr = addr - .encapsulate(multiaddr(`/ipfs/${identity.id}`)).toString() - .replace('0.0.0.0', '127.0.0.1') - - dialerNode.swarm.connect(targetAddr, done) - }) - } - - function connectNodes (remoteNode, ipn, done) { - series([ - (cb) => wire(remoteNode, ipn, cb), - // 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) - } - - function addNode (num, done) { - num = leftPad(num, 3, 0) + }) - const apiUrl = `/ip4/127.0.0.1/tcp/31${num}` - const remoteNode = new API(apiUrl) + it('3 peers', function (done) { + this.timeout(60 * 1000) - connectNodes(remoteNode, inProcNode, (err) => done(err, remoteNode)) - } + let blocks + const remoteNodes = [] - describe('fetches a remote block', () => { - it('2 peers', function (done) { - this.timeout(10 * 1000) - - let remoteNode - let block - waterfall([ - (cb) => parallel([ - (cb) => makeBlock(cb), - (cb) => addNode(13, cb) - ], cb), - (res, cb) => { - block = res[0] - remoteNode = res[1] - cb() - }, - (cb) => remoteNode.block.put(block, cb), - (key, cb) => inProcNode.block.get(block.cid, cb), - (b, cb) => { - expect(b.data).to.eql(block.data) - cb() + series([ + (cb) => parallel(_.range(6).map((i) => makeBlock), (err, _blocks) => { + expect(err).to.not.exist() + blocks = _blocks + cb() + }), + (cb) => addNode(8, inProcNode, (err, _ipfs) => { + remoteNodes.push(_ipfs) + cb(err) + }), + (cb) => addNode(7, inProcNode, (err, _ipfs) => { + remoteNodes.push(_ipfs) + cb(err) + }), + (cb) => connectNodes(remoteNodes[0], remoteNodes[1], cb), + (cb) => remoteNodes[0].block.put(blocks[0], cb), + (cb) => remoteNodes[0].block.put(blocks[1], cb), + (cb) => remoteNodes[1].block.put(blocks[2], cb), + (cb) => remoteNodes[1].block.put(blocks[3], cb), + (cb) => inProcNode.block.put(blocks[4], cb), + (cb) => inProcNode.block.put(blocks[5], cb), + // 3. Fetch blocks on all nodes + (cb) => parallel(_.range(6).map((i) => (cbI) => { + const check = (n, cid, callback) => { + n.block.get(cid, (err, b) => { + expect(err).to.not.exist() + expect(b).to.eql(blocks[i]) + callback() + }) } - ], done) - }) - it('3 peers', function (done) { - this.timeout(30 * 1000) - - let blocks - const remoteNodes = [] - - series([ - (cb) => parallel(_.range(6).map((i) => makeBlock), (err, _blocks) => { - expect(err).to.not.exist() - blocks = _blocks - cb() - }), - (cb) => addNode(8, (err, _ipfs) => { - remoteNodes.push(_ipfs) - cb(err) - }), - (cb) => addNode(7, (err, _ipfs) => { - remoteNodes.push(_ipfs) - cb(err) - }), - (cb) => connectNodes(remoteNodes[0], remoteNodes[1], cb), - (cb) => remoteNodes[0].block.put(blocks[0], cb), - (cb) => remoteNodes[0].block.put(blocks[1], cb), - (cb) => remoteNodes[1].block.put(blocks[2], cb), - (cb) => remoteNodes[1].block.put(blocks[3], cb), - (cb) => inProcNode.block.put(blocks[4], cb), - (cb) => inProcNode.block.put(blocks[5], cb), - // 3. Fetch blocks on all nodes - (cb) => parallel(_.range(6).map((i) => (cbI) => { - const check = (n, cid, callback) => { - n.block.get(cid, (err, b) => { - expect(err).to.not.exist() - expect(b).to.eql(blocks[i]) - callback() - }) - } - - series([ - (cbJ) => check(remoteNodes[0], blocks[i].cid, cbJ), - (cbJ) => check(remoteNodes[1], blocks[i].cid, cbJ), - (cbJ) => check(inProcNode, blocks[i].cid, cbJ) - ], cbI) - }), cb) - ], done) - }) + series([ + (cbJ) => check(remoteNodes[0], blocks[i].cid, cbJ), + (cbJ) => check(remoteNodes[1], blocks[i].cid, cbJ), + (cbJ) => check(inProcNode, blocks[i].cid, cbJ) + ], cbI) + }), cb) + ], done) }) + }) - describe('fetches a remote file', () => { - it('2 peers', (done) => { - const file = Buffer.from(`I love IPFS <3 ${Math.random()}`) - - waterfall([ - // 0. Start node - (cb) => addNode(12, cb), - // 1. Add file to tmp instance - (remote, cb) => { - remote.files.add([{path: 'awesome.txt', content: file}], cb) - }, - // 2. Request file from local instance - (filesAdded, cb) => inProcNode.files.cat(filesAdded[0].hash, cb) - ], (err, data) => { - expect(err).to.not.exist() - expect(data).to.eql(file) - done() - }) + describe('transfer a file between', () => { + it('2 peers', (done) => { + // TODO make this test more interesting (10Mb file) + const file = Buffer.from(`I love IPFS <3 ${Math.random()}`) + + waterfall([ + // 0. Start node + (cb) => addNode(12, inProcNode, cb), + // 1. Add file to tmp instance + (remote, cb) => { + remote.files.add([{path: 'awesome.txt', content: file}], cb) + }, + // 2. Request file from local instance + (filesAdded, cb) => inProcNode.files.cat(filesAdded[0].hash, cb) + ], (err, data) => { + expect(err).to.not.exist() + expect(data).to.eql(file) + done() }) }) }) - describe('bitswap API', () => { + describe('api', () => { let node before(function (done) { @@ -243,8 +241,7 @@ describe('bitswap', function () { }) it('throws if offline', () => { - expect(() => node.bitswap.unwant('my key')) - .to.throw(/online/) + expect(() => node.bitswap.unwant('my key')).to.throw(/online/) }) }) diff --git a/test/core/bootstrap.spec.js b/test/core/bootstrap.spec.js index 52e409434a..3f291c5696 100644 --- a/test/core/bootstrap.spec.js +++ b/test/core/bootstrap.spec.js @@ -18,7 +18,8 @@ describe('bootstrap', () => { let node - before((done) => { + before(function (done) { + this.timeout(40 * 1000) node = new IPFS({ repo: createTempRepo(), init: { diff --git a/test/core/create-node.spec.js b/test/core/create-node.spec.js index 8660ea8a4b..011c1b7a78 100644 --- a/test/core/create-node.spec.js +++ b/test/core/create-node.spec.js @@ -15,10 +15,8 @@ const IPFS = require('../../src/core') const createTempRepo = require('../utils/create-repo-nodejs.js') describe('create node', function () { - this.timeout(40 * 1000) - it('custom repoPath', function (done) { - this.timeout(40 * 1000) + this.timeout(80 * 1000) const node = new IPFS({ repo: '/tmp/ipfs-repo-' + Math.random(), @@ -43,7 +41,7 @@ describe('create node', function () { }) it('custom repo', function (done) { - this.timeout(40 * 1000) + this.timeout(80 * 1000) const node = new IPFS({ repo: createTempRepo(), @@ -67,7 +65,7 @@ describe('create node', function () { }) it('IPFS.createNode', function (done) { - this.timeout(40 * 1000) + this.timeout(80 * 1000) const node = IPFS.createNode({ repo: createTempRepo(), @@ -94,12 +92,12 @@ describe('create node', function () { }) it('init: { bits: 1024 }', function (done) { - this.timeout(40 * 1000) + this.timeout(80 * 1000) const node = new IPFS({ repo: createTempRepo(), init: { - bits: 1024 + bits: 512 }, config: { Addresses: { @@ -121,7 +119,7 @@ describe('create node', function () { }) it('init: false errors (start default: true)', function (done) { - this.timeout(40 * 1000) + this.timeout(80 * 1000) const node = new IPFS({ repo: createTempRepo(), @@ -139,7 +137,7 @@ describe('create node', function () { }) it('init: false, start: false', function (done) { - this.timeout(40 * 1000) + this.timeout(80 * 1000) const node = new IPFS({ repo: createTempRepo(), @@ -169,7 +167,7 @@ describe('create node', function () { }) it('init: true, start: false', function (done) { - this.timeout(40 * 1000) + this.timeout(80 * 1000) const node = new IPFS({ repo: createTempRepo(), @@ -191,7 +189,7 @@ describe('create node', function () { }) it('init: true, start: false, use callback', function (done) { - this.timeout(40 * 1000) + this.timeout(80 * 1000) const node = new IPFS({ repo: createTempRepo(), @@ -210,7 +208,7 @@ describe('create node', function () { }) it('overload config', function (done) { - this.timeout(40 * 1000) + this.timeout(80 * 1000) if (!isNode) { return done() } @@ -229,10 +227,7 @@ describe('create node', function () { node.config.get((err, config) => { expect(err).to.not.exist() - expect(config.Addresses.Swarm).to.eql( - ['/ip4/127.0.0.1/tcp/9977'] - ) - + expect(config.Addresses.Swarm).to.eql(['/ip4/127.0.0.1/tcp/9977']) expect(config.Bootstrap).to.eql([]) node.stop(done) @@ -241,7 +236,7 @@ describe('create node', function () { }) it('start and stop, start and stop', function (done) { - this.timeout(40 * 1000) + this.timeout(80 * 1000) const node = new IPFS({ repo: createTempRepo(), @@ -262,7 +257,7 @@ describe('create node', function () { }) it('stop as promised', function (done) { - this.timeout(40 * 1000) + this.timeout(80 * 1000) const node = new IPFS({ repo: createTempRepo(), @@ -282,7 +277,7 @@ describe('create node', function () { }) it('can start node twice without crash', function (done) { - this.timeout(40 * 1000) + this.timeout(80 * 1000) const options = { repo: createTempRepo(), @@ -301,7 +296,7 @@ describe('create node', function () { (cb) => node.stop(cb), (cb) => { node = new IPFS(options) - node.on('error', cb) + node.once('error', cb) node.once('start', cb) }, (cb) => node.stop(cb) diff --git a/test/gateway/index.js b/test/gateway/index.js index 3471c915ee..861fa9ff87 100644 --- a/test/gateway/index.js +++ b/test/gateway/index.js @@ -10,6 +10,7 @@ const API = require('../../src/http') const loadFixture = require('aegir/fixtures') const os = require('os') const path = require('path') +const hat = require('hat') const fileType = require('file-type') const bigFile = loadFixture(__dirname, '../../node_modules/interface-ipfs-core/test/fixtures/15mb.random', 'ipfs') @@ -21,16 +22,15 @@ const directoryContent = { 'cat-folder/cat.jpg': loadFixture(__dirname, './test-folder/cat-folder/cat.jpg', 'ipfs') } -describe('HTTP Gateway', () => { +describe('HTTP Gateway', function () { + this.timeout(80 * 1000) + let http = {} let gateway before(function (done) { - this.timeout(20 * 1000) - const repoPath = path.join( - os.tmpdir(), - '/ipfs-' + Math.random().toString().substring(2, 8) + '-' + Date.now() - ) + this.timeout(60 * 1000) + const repoPath = path.join(os.tmpdir(), '/ipfs-' + hat()) http.api = new API(repoPath, { Bootstrap: [], @@ -114,141 +114,138 @@ describe('HTTP Gateway', () => { after((done) => http.api.stop(done)) - describe('## HTTP Gateway', function () { - this.timeout(20 * 1000) - it('returns 400 for request without argument', (done) => { - gateway.inject({ - method: 'GET', - url: '/ipfs' - }, (res) => { - expect(res.statusCode).to.equal(400) - expect(res.result.Message).to.be.a('string') - done() - }) + it('returns 400 for request without argument', (done) => { + gateway.inject({ + method: 'GET', + url: '/ipfs' + }, (res) => { + expect(res.statusCode).to.equal(400) + expect(res.result.Message).to.be.a('string') + done() }) + }) - it('400 for request with invalid argument', (done) => { - gateway.inject({ - method: 'GET', - url: '/ipfs/invalid' - }, (res) => { - expect(res.statusCode).to.equal(400) - expect(res.result.Message).to.be.a('string') - done() - }) + it('400 for request with invalid argument', (done) => { + gateway.inject({ + method: 'GET', + url: '/ipfs/invalid' + }, (res) => { + expect(res.statusCode).to.equal(400) + expect(res.result.Message).to.be.a('string') + done() }) + }) - it('valid hash', (done) => { - gateway.inject({ - method: 'GET', - url: '/ipfs/QmT78zSuBmuS4z925WZfrqQ1qHaJ56DQaTfyMUF7F8ff5o' - }, (res) => { - expect(res.statusCode).to.equal(200) - expect(res.rawPayload).to.eql(Buffer.from('hello world' + '\n')) - expect(res.payload).to.equal('hello world' + '\n') - done() - }) + it('valid hash', (done) => { + gateway.inject({ + method: 'GET', + url: '/ipfs/QmT78zSuBmuS4z925WZfrqQ1qHaJ56DQaTfyMUF7F8ff5o' + }, (res) => { + expect(res.statusCode).to.equal(200) + expect(res.rawPayload).to.eql(Buffer.from('hello world' + '\n')) + expect(res.payload).to.equal('hello world' + '\n') + done() }) + }) - it('stream a large file', (done) => { - let bigFileHash = 'Qme79tX2bViL26vNjPsF3DP1R9rMKMvnPYJiKTTKPrXJjq' - - gateway.inject({ - method: 'GET', - url: '/ipfs/' + bigFileHash - }, (res) => { - expect(res.statusCode).to.equal(200) - expect(res.rawPayload).to.eql(bigFile) - done() - }) + it('stream a large file', (done) => { + let bigFileHash = 'Qme79tX2bViL26vNjPsF3DP1R9rMKMvnPYJiKTTKPrXJjq' + + gateway.inject({ + method: 'GET', + url: '/ipfs/' + bigFileHash + }, (res) => { + expect(res.statusCode).to.equal(200) + expect(res.rawPayload).to.eql(bigFile) + done() }) + }) - it('load a non text file', (done) => { - let kitty = 'QmW2WQi7j6c7UgJTarActp7tDNikE4B2qXtFCfLPdsgaTQ/cat.jpg' + it('load a non text file', (done) => { + let kitty = 'QmW2WQi7j6c7UgJTarActp7tDNikE4B2qXtFCfLPdsgaTQ/cat.jpg' - gateway.inject({ - method: 'GET', - url: '/ipfs/' + kitty - }, (res) => { - expect(res.statusCode).to.equal(200) - expect(res.headers['content-type']).to.equal('image/jpeg') + gateway.inject({ + method: 'GET', + url: '/ipfs/' + kitty + }, (res) => { + expect(res.statusCode).to.equal(200) + expect(res.headers['content-type']).to.equal('image/jpeg') - let fileSignature = fileType(res.rawPayload) - expect(fileSignature.mime).to.equal('image/jpeg') - expect(fileSignature.ext).to.equal('jpg') + let fileSignature = fileType(res.rawPayload) + expect(fileSignature.mime).to.equal('image/jpeg') + expect(fileSignature.ext).to.equal('jpg') - done() - }) + done() }) + }) - it('load a directory', (done) => { - let dir = 'QmW2WQi7j6c7UgJTarActp7tDNikE4B2qXtFCfLPdsgaTQ/' - - gateway.inject({ - method: 'GET', - url: '/ipfs/' + dir - }, (res) => { - expect(res.statusCode).to.equal(200) - expect(res.headers['content-type']).to.equal('text/html; charset=utf-8') - - // check if the cat picture is in the payload as a way to check - // if this is an index of this directory - let listedFile = res.payload.match(/\/ipfs\/QmW2WQi7j6c7UgJTarActp7tDNikE4B2qXtFCfLPdsgaTQ\/cat\.jpg/g) - expect(listedFile).to.have.lengthOf(1) - done() - }) + it('load a directory', (done) => { + let dir = 'QmW2WQi7j6c7UgJTarActp7tDNikE4B2qXtFCfLPdsgaTQ/' + + gateway.inject({ + method: 'GET', + url: '/ipfs/' + dir + }, (res) => { + expect(res.statusCode).to.equal(200) + expect(res.headers['content-type']).to.equal('text/html; charset=utf-8') + + // check if the cat picture is in the payload as a way to check + // if this is an index of this directory + let listedFile = res.payload.match(/\/ipfs\/QmW2WQi7j6c7UgJTarActp7tDNikE4B2qXtFCfLPdsgaTQ\/cat\.jpg/g) + expect(listedFile).to.have.lengthOf(1) + done() }) + }) - it('load a webpage index.html', (done) => { - let dir = 'QmbQD7EMEL1zeebwBsWEfA3ndgSS6F7S6iTuwuqasPgVRi/index.html' - - gateway.inject({ - method: 'GET', - url: '/ipfs/' + dir - }, (res) => { - expect(res.statusCode).to.equal(200) - expect(res.rawPayload).to.deep.equal(directoryContent['index.html']) - done() - }) + it('load a webpage index.html', (done) => { + let dir = 'QmbQD7EMEL1zeebwBsWEfA3ndgSS6F7S6iTuwuqasPgVRi/index.html' + + gateway.inject({ + method: 'GET', + url: '/ipfs/' + dir + }, (res) => { + expect(res.statusCode).to.equal(200) + expect(res.rawPayload).to.deep.equal(directoryContent['index.html']) + done() }) + }) - it('load a webpage {hash}/nested-folder/nested.html', (done) => { - let dir = 'QmbQD7EMEL1zeebwBsWEfA3ndgSS6F7S6iTuwuqasPgVRi/nested-folder/nested.html' - - gateway.inject({ - method: 'GET', - url: '/ipfs/' + dir - }, (res) => { - expect(res.statusCode).to.equal(200) - expect(res.rawPayload).to.deep.equal(directoryContent['nested-folder/nested.html']) - done() - }) + it('load a webpage {hash}/nested-folder/nested.html', (done) => { + let dir = 'QmbQD7EMEL1zeebwBsWEfA3ndgSS6F7S6iTuwuqasPgVRi/nested-folder/nested.html' + + gateway.inject({ + method: 'GET', + url: '/ipfs/' + dir + }, (res) => { + expect(res.statusCode).to.equal(200) + expect(res.rawPayload).to.deep.equal(directoryContent['nested-folder/nested.html']) + done() }) + }) - it('redirect to generated index', (done) => { - let dir = 'QmW2WQi7j6c7UgJTarActp7tDNikE4B2qXtFCfLPdsgaTQ' - - gateway.inject({ - method: 'GET', - url: '/ipfs/' + dir - }, (res) => { - expect(res.statusCode).to.equal(301) - expect(res.headers['location']).to.equal('/ipfs/QmW2WQi7j6c7UgJTarActp7tDNikE4B2qXtFCfLPdsgaTQ/') - done() - }) + it('redirect to generated index', (done) => { + let dir = 'QmW2WQi7j6c7UgJTarActp7tDNikE4B2qXtFCfLPdsgaTQ' + + gateway.inject({ + method: 'GET', + url: '/ipfs/' + dir + }, (res) => { + expect(res.statusCode).to.equal(301) + expect(res.headers['location']).to.equal('/ipfs/QmW2WQi7j6c7UgJTarActp7tDNikE4B2qXtFCfLPdsgaTQ/') + done() }) + }) + + it('redirect to webpage index.html', (done) => { + let dir = 'QmbQD7EMEL1zeebwBsWEfA3ndgSS6F7S6iTuwuqasPgVRi/' - it('redirect to webpage index.html', (done) => { - let dir = 'QmbQD7EMEL1zeebwBsWEfA3ndgSS6F7S6iTuwuqasPgVRi/' - - gateway.inject({ - method: 'GET', - url: '/ipfs/' + dir - }, (res) => { - expect(res.statusCode).to.equal(302) - expect(res.headers['location']).to.equal('/ipfs/QmbQD7EMEL1zeebwBsWEfA3ndgSS6F7S6iTuwuqasPgVRi/index.html') - done() - }) + gateway.inject({ + method: 'GET', + url: '/ipfs/' + dir + }, (res) => { + expect(res.statusCode).to.equal(302) + expect(res.headers['location']).to.equal('/ipfs/QmbQD7EMEL1zeebwBsWEfA3ndgSS6F7S6iTuwuqasPgVRi/index.html') + done() }) }) }) diff --git a/test/http-api/extra/bootstrap.js b/test/http-api/extra/bootstrap.js index ebde07318e..1c6ad4ca60 100644 --- a/test/http-api/extra/bootstrap.js +++ b/test/http-api/extra/bootstrap.js @@ -12,7 +12,9 @@ module.exports = (ctl) => { const validIp4 = '/ip4/101.236.176.52/tcp/4001/ipfs/QmSoLnSGccFuZQJzRadHn95W2CrSFmZuTdDWP8HXaHca9z' let peers - describe('.add', () => { + describe('.add', function () { + this.timeout(40 * 1000) + it('returns an error when called with an invalid arg', (done) => { ctl.bootstrap.add(invalidArg, (err) => { expect(err).to.be.an.instanceof(Error) diff --git a/test/http-api/index.js b/test/http-api/index.js index 85fc528a7d..374f50485c 100644 --- a/test/http-api/index.js +++ b/test/http-api/index.js @@ -19,7 +19,7 @@ describe('HTTP API', () => { let http = {} before(function (done) { - this.timeout(40 * 1000) + this.timeout(60 * 1000) const options = { enablePubsubExperiment: true } http.api = new API(repoTests, null, options) diff --git a/test/utils/on-and-off.js b/test/utils/on-and-off.js index d9886275ff..8a79c660ef 100644 --- a/test/utils/on-and-off.js +++ b/test/utils/on-and-off.js @@ -2,6 +2,7 @@ 'use strict' const Factory = require('../utils/ipfs-factory-daemon') +const hat = require('hat') const chai = require('chai') const dirtyChai = require('dirty-chai') const expect = chai.expect @@ -17,15 +18,16 @@ function off (tests) { let repoPath before(function () { - this.timeout(30 * 1000) - repoPath = os.tmpdir() + '/ipfs-' + Math.random().toString().substring(2, 16) + this.timeout(60 * 1000) + + repoPath = os.tmpdir() + '/ipfs-' + hat() thing.ipfs = ipfsExec(repoPath) thing.ipfs.repoPath = repoPath return thing.ipfs('init') }) after(function (done) { - this.timeout(20 * 1000) + this.timeout(26 * 1000) clean(repoPath) setImmediate(done) }) @@ -43,7 +45,7 @@ function on (tests) { // CI takes longer to instantiate the daemon, // so we need to increase the timeout for the // before step - this.timeout(30 * 1000) + this.timeout(60 * 1000) factory = new Factory() @@ -56,7 +58,7 @@ function on (tests) { }) after(function (done) { - this.timeout(20 * 1000) + this.timeout(60 * 1000) factory.dismantle(done) })