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

Commit 70b8cd7

Browse files
authoredNov 26, 2017
chore: make Travis a little bit more happy (#1109)
* wip * refactor bitswap tests * travis, you can do it! * bora lá * last mile * one more time * another round * one more time
1 parent 93cc273 commit 70b8cd7

12 files changed

+314
-321
lines changed
 

‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
"expose-loader": "^0.7.4",
7676
"form-data": "^2.3.1",
7777
"hat": "0.0.3",
78-
"interface-ipfs-core": "~0.36.8",
78+
"interface-ipfs-core": "~0.36.11",
7979
"ipfsd-ctl": "~0.25.1",
8080
"left-pad": "^1.2.0",
8181
"lodash": "^4.17.4",

‎test/cli/files.js

+13-13
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ describe('files', () => runOnAndOff((thing) => {
107107
})
108108

109109
it('add with progress', function () {
110-
this.timeout(20 * 1000)
110+
this.timeout(30 * 1000)
111111

112112
return ipfs('files add -p src/init-files/init-docs/readme')
113113
.then((out) => {
@@ -117,7 +117,7 @@ describe('files', () => runOnAndOff((thing) => {
117117
})
118118

119119
it('add', function () {
120-
this.timeout(20 * 1000)
120+
this.timeout(30 * 1000)
121121

122122
return ipfs('files add src/init-files/init-docs/readme')
123123
.then((out) => {
@@ -127,7 +127,7 @@ describe('files', () => runOnAndOff((thing) => {
127127
})
128128

129129
it('add alias', function () {
130-
this.timeout(20 * 1000)
130+
this.timeout(30 * 1000)
131131

132132
return ipfs('add src/init-files/init-docs/readme')
133133
.then((out) => {
@@ -137,7 +137,7 @@ describe('files', () => runOnAndOff((thing) => {
137137
})
138138

139139
it('add recursively test', function () {
140-
this.timeout(20 * 1000)
140+
this.timeout(60 * 1000)
141141

142142
return ipfs('files add -r test/fixtures/test-data/recursive-get-dir')
143143
.then((out) => {
@@ -146,7 +146,7 @@ describe('files', () => runOnAndOff((thing) => {
146146
})
147147

148148
it('add directory with trailing slash test', function () {
149-
this.timeout(20 * 1000)
149+
this.timeout(30 * 1000)
150150

151151
return ipfs('files add -r test/fixtures/test-data/recursive-get-dir/')
152152
.then((out) => {
@@ -155,7 +155,7 @@ describe('files', () => runOnAndOff((thing) => {
155155
})
156156

157157
it('add and wrap with a directory', function () {
158-
this.timeout(20 * 1000)
158+
this.timeout(30 * 1000)
159159

160160
return ipfs('add -w src/init-files/init-docs/readme').then((out) => {
161161
expect(out).to.be.eql([
@@ -166,7 +166,7 @@ describe('files', () => runOnAndOff((thing) => {
166166
})
167167

168168
it('add with cid-version=0', function () {
169-
this.timeout(20 * 1000)
169+
this.timeout(30 * 1000)
170170

171171
return ipfs('add src/init-files/init-docs/readme --cid-version=0').then((out) => {
172172
expect(out)
@@ -184,7 +184,7 @@ describe('files', () => runOnAndOff((thing) => {
184184
//
185185
// This retains feature parity without having to implement raw-leaves.
186186
it('add with cid-version=1', function () {
187-
this.timeout(20 * 1000)
187+
this.timeout(30 * 1000)
188188

189189
return new Promise((resolve, reject) => {
190190
ipfs('add src/init-files/init-docs/readme --cid-version=1')
@@ -214,7 +214,7 @@ describe('files', () => runOnAndOff((thing) => {
214214
//
215215
// This retains feature parity without having to implement raw-leaves.
216216
it('add with cid-version=1 and raw-leaves=true', function () {
217-
this.timeout(20 * 1000)
217+
this.timeout(30 * 1000)
218218

219219
return new Promise((resolve, reject) => {
220220
ipfs('add src/init-files/init-docs/readme --cid-version=1 --raw-leaves=true')
@@ -227,7 +227,7 @@ describe('files', () => runOnAndOff((thing) => {
227227
})
228228

229229
it('add --quiet', function () {
230-
this.timeout(20 * 1000)
230+
this.timeout(30 * 1000)
231231

232232
return ipfs('files add -q src/init-files/init-docs/readme')
233233
.then((out) => {
@@ -237,7 +237,7 @@ describe('files', () => runOnAndOff((thing) => {
237237
})
238238

239239
it('add --quieter', function () {
240-
this.timeout(20 * 1000)
240+
this.timeout(30 * 1000)
241241

242242
return ipfs('files add -Q -w test/fixtures/test-data/hello test/test-data/node.json')
243243
.then((out) => {
@@ -247,7 +247,7 @@ describe('files', () => runOnAndOff((thing) => {
247247
})
248248

249249
it('add --silent', function () {
250-
this.timeout(20 * 1000)
250+
this.timeout(30 * 1000)
251251

252252
return ipfs('files add --silent src/init-files/init-docs/readme')
253253
.then((out) => {
@@ -257,7 +257,7 @@ describe('files', () => runOnAndOff((thing) => {
257257
})
258258

259259
it('cat', function () {
260-
this.timeout(20 * 1000)
260+
this.timeout(30 * 1000)
261261

262262
return ipfs('files cat QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB')
263263
.then((out) => {

‎test/cli/id.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ describe('id', () => runOnAndOff((thing) => {
88
let ipfs
99

1010
before(function () {
11-
this.timeout(40 * 1000)
11+
this.timeout(60 * 1000)
1212
ipfs = thing.ipfs
1313
})
1414

1515
it('get the id', function () {
16-
this.timeout(40 * 1000)
16+
this.timeout(60 * 1000)
1717

1818
return ipfs('id').then((res) => {
1919
const id = JSON.parse(res)

‎test/cli/pubsub.js

+26-27
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ describe('pubsub', function () {
2626
const topicC = 'nonscentsC'
2727

2828
before(function (done) {
29-
this.timeout(40 * 1000)
29+
this.timeout(60 * 1000)
3030

3131
instanceFactory = new InstanceFactory()
3232
instanceFactory.spawnNode((err, _node) => {
@@ -73,7 +73,7 @@ describe('pubsub', function () {
7373
})
7474

7575
it('ls', function () {
76-
this.timeout(40 * 1000)
76+
this.timeout(80 * 1000)
7777

7878
const sub = cli(`pubsub sub ${topicB}`)
7979

@@ -108,32 +108,31 @@ describe('pubsub', function () {
108108
})
109109
}
110110

111-
series(
112-
[
113-
(cb) => httpApi.id((err, peerInfo) => {
114-
expect(err).to.not.exist()
115-
peerAddress = peerInfo.addresses[0]
116-
expect(peerAddress).to.exist()
117-
cb()
118-
}),
119-
(cb) => node.id((err, peerInfo) => {
120-
expect(err).to.not.exist()
121-
instancePeerId = peerInfo.id.toString()
122-
cb()
123-
}),
124-
(cb) => node.swarm.connect(peerAddress, cb),
125-
(cb) => node.pubsub.subscribe(topicC, handler, cb)
126-
],
127-
(err) => {
111+
series([
112+
(cb) => httpApi.id((err, peerInfo) => {
128113
expect(err).to.not.exist()
129-
sub = cli(`pubsub sub ${topicC}`)
130-
131-
return Promise.all([
132-
sub.catch(ignoreKill),
133-
delay(1000)
134-
.then(() => cli(`pubsub pub ${topicC} world`))
135-
])
136-
})
114+
peerAddress = peerInfo.addresses[0]
115+
expect(peerAddress).to.exist()
116+
cb()
117+
}),
118+
(cb) => node.id((err, peerInfo) => {
119+
expect(err).to.not.exist()
120+
instancePeerId = peerInfo.id.toString()
121+
cb()
122+
}),
123+
(cb) => node.swarm.connect(peerAddress, cb),
124+
(cb) => node.pubsub.subscribe(topicC, handler, cb)
125+
],
126+
(err) => {
127+
expect(err).to.not.exist()
128+
sub = cli(`pubsub sub ${topicC}`)
129+
130+
return Promise.all([
131+
sub.catch(ignoreKill),
132+
delay(1000)
133+
.then(() => cli(`pubsub pub ${topicC} world`))
134+
])
135+
})
137136
})
138137
})
139138

‎test/cli/swarm.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ describe('swarm', () => {
1818
before(function (done) {
1919
// CI takes longer to instantiate the daemon, so we need to increase the
2020
// timeout for the before step
21-
this.timeout(60 * 1000)
21+
this.timeout(80 * 1000)
2222

2323
factory = new Factory()
2424

@@ -46,7 +46,7 @@ describe('swarm', () => {
4646
after((done) => factory.dismantle(done))
4747

4848
describe('daemon on (through http-api)', function () {
49-
this.timeout(40 * 1000)
49+
this.timeout(60 * 1000)
5050

5151
it('connect', () => {
5252
return ipfsA('swarm', 'connect', bMultiaddr).then((out) => {

‎test/core/bitswap.spec.js

+125-128
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,44 @@ function makeBlock (callback) {
3434
})
3535
}
3636

37+
function wire (targetNode, dialerNode, callback) {
38+
targetNode.id((err, identity) => {
39+
expect(err).to.not.exist()
40+
const addr = identity.addresses
41+
.map((addr) => multiaddr(addr.toString().split('ipfs')[0]))
42+
.filter((addr) => _.includes(addr.protoNames(), 'ws'))[0]
43+
44+
if (!addr) {
45+
// Note: the browser doesn't have a websockets listening addr
46+
return callback()
47+
}
48+
49+
const targetAddr = addr
50+
.encapsulate(multiaddr(`/ipfs/${identity.id}`)).toString()
51+
.replace('0.0.0.0', '127.0.0.1')
52+
53+
dialerNode.swarm.connect(targetAddr, callback)
54+
})
55+
}
56+
57+
function connectNodes (remoteNode, inProcNode, callback) {
58+
series([
59+
(cb) => wire(remoteNode, inProcNode, cb),
60+
// need timeout so we wait for identify to happen.
61+
// This call is just to ensure identify happened
62+
(cb) => setTimeout(() => wire(inProcNode, remoteNode, cb), 500)
63+
], callback)
64+
}
65+
66+
function addNode (num, inProcNode, callback) {
67+
num = leftPad(num, 3, 0)
68+
69+
const apiUrl = `/ip4/127.0.0.1/tcp/31${num}`
70+
const remoteNode = new API(apiUrl)
71+
72+
connectNodes(remoteNode, inProcNode, (err) => callback(err, remoteNode))
73+
}
74+
3775
describe('bitswap', function () {
3876
this.timeout(80 * 1000)
3977

@@ -42,7 +80,7 @@ describe('bitswap', function () {
4280
beforeEach(function (done) {
4381
this.timeout(60 * 1000)
4482

45-
let config = {
83+
let options = {
4684
repo: createTempRepo(),
4785
config: {
4886
Addresses: {
@@ -58,7 +96,7 @@ describe('bitswap', function () {
5896
}
5997

6098
if (isNode) {
61-
config = Object.assign(config, {
99+
options = Object.assign(options, {
62100
config: {
63101
Addresses: {
64102
Swarm: ['/ip4/127.0.0.1/tcp/0']
@@ -67,150 +105,110 @@ describe('bitswap', function () {
67105
})
68106
}
69107

70-
inProcNode = new IPFS(config)
71-
inProcNode.on('start', () => done())
108+
inProcNode = new IPFS(options)
109+
inProcNode.on('ready', () => done())
72110
})
73111

74112
afterEach(function (done) {
75-
this.timeout(30 * 1000)
76-
113+
this.timeout(60 * 1000)
77114
inProcNode.stop(() => done())
78115
})
79116

80-
describe('connections', () => {
81-
function wire (targetNode, dialerNode, done) {
82-
targetNode.id((err, identity) => {
83-
expect(err).to.not.exist()
84-
const addr = identity.addresses
85-
.map((addr) => multiaddr(addr.toString().split('ipfs')[0]))
86-
.filter((addr) => _.includes(addr.protoNames(), 'ws'))[0]
117+
describe('transfer a block between', () => {
118+
it('2 peers', function (done) {
119+
this.timeout(40 * 1000)
87120

88-
if (!addr) {
89-
// Note: the browser doesn't have a websockets listening addr
90-
return done()
121+
let remoteNode
122+
let block
123+
waterfall([
124+
(cb) => parallel([
125+
(cb) => makeBlock(cb),
126+
(cb) => addNode(13, inProcNode, cb)
127+
], cb),
128+
(res, cb) => {
129+
block = res[0]
130+
remoteNode = res[1]
131+
cb()
132+
},
133+
(cb) => remoteNode.block.put(block, cb),
134+
(key, cb) => inProcNode.block.get(block.cid, cb),
135+
(b, cb) => {
136+
expect(b.data).to.eql(block.data)
137+
cb()
91138
}
92-
93-
const targetAddr = addr
94-
.encapsulate(multiaddr(`/ipfs/${identity.id}`)).toString()
95-
.replace('0.0.0.0', '127.0.0.1')
96-
97-
dialerNode.swarm.connect(targetAddr, done)
98-
})
99-
}
100-
101-
function connectNodes (remoteNode, ipn, done) {
102-
series([
103-
(cb) => wire(remoteNode, ipn, cb),
104-
// need timeout so we wait for identify to happen.
105-
// This call is just to ensure identify happened
106-
(cb) => setTimeout(() => wire(ipn, remoteNode, cb), 300)
107139
], done)
108-
}
109-
110-
function addNode (num, done) {
111-
num = leftPad(num, 3, 0)
140+
})
112141

113-
const apiUrl = `/ip4/127.0.0.1/tcp/31${num}`
114-
const remoteNode = new API(apiUrl)
142+
it('3 peers', function (done) {
143+
this.timeout(60 * 1000)
115144

116-
connectNodes(remoteNode, inProcNode, (err) => done(err, remoteNode))
117-
}
145+
let blocks
146+
const remoteNodes = []
118147

119-
describe('fetches a remote block', () => {
120-
it('2 peers', function (done) {
121-
this.timeout(10 * 1000)
122-
123-
let remoteNode
124-
let block
125-
waterfall([
126-
(cb) => parallel([
127-
(cb) => makeBlock(cb),
128-
(cb) => addNode(13, cb)
129-
], cb),
130-
(res, cb) => {
131-
block = res[0]
132-
remoteNode = res[1]
133-
cb()
134-
},
135-
(cb) => remoteNode.block.put(block, cb),
136-
(key, cb) => inProcNode.block.get(block.cid, cb),
137-
(b, cb) => {
138-
expect(b.data).to.eql(block.data)
139-
cb()
148+
series([
149+
(cb) => parallel(_.range(6).map((i) => makeBlock), (err, _blocks) => {
150+
expect(err).to.not.exist()
151+
blocks = _blocks
152+
cb()
153+
}),
154+
(cb) => addNode(8, inProcNode, (err, _ipfs) => {
155+
remoteNodes.push(_ipfs)
156+
cb(err)
157+
}),
158+
(cb) => addNode(7, inProcNode, (err, _ipfs) => {
159+
remoteNodes.push(_ipfs)
160+
cb(err)
161+
}),
162+
(cb) => connectNodes(remoteNodes[0], remoteNodes[1], cb),
163+
(cb) => remoteNodes[0].block.put(blocks[0], cb),
164+
(cb) => remoteNodes[0].block.put(blocks[1], cb),
165+
(cb) => remoteNodes[1].block.put(blocks[2], cb),
166+
(cb) => remoteNodes[1].block.put(blocks[3], cb),
167+
(cb) => inProcNode.block.put(blocks[4], cb),
168+
(cb) => inProcNode.block.put(blocks[5], cb),
169+
// 3. Fetch blocks on all nodes
170+
(cb) => parallel(_.range(6).map((i) => (cbI) => {
171+
const check = (n, cid, callback) => {
172+
n.block.get(cid, (err, b) => {
173+
expect(err).to.not.exist()
174+
expect(b).to.eql(blocks[i])
175+
callback()
176+
})
140177
}
141-
], done)
142-
})
143178

144-
it('3 peers', function (done) {
145-
this.timeout(30 * 1000)
146-
147-
let blocks
148-
const remoteNodes = []
149-
150-
series([
151-
(cb) => parallel(_.range(6).map((i) => makeBlock), (err, _blocks) => {
152-
expect(err).to.not.exist()
153-
blocks = _blocks
154-
cb()
155-
}),
156-
(cb) => addNode(8, (err, _ipfs) => {
157-
remoteNodes.push(_ipfs)
158-
cb(err)
159-
}),
160-
(cb) => addNode(7, (err, _ipfs) => {
161-
remoteNodes.push(_ipfs)
162-
cb(err)
163-
}),
164-
(cb) => connectNodes(remoteNodes[0], remoteNodes[1], cb),
165-
(cb) => remoteNodes[0].block.put(blocks[0], cb),
166-
(cb) => remoteNodes[0].block.put(blocks[1], cb),
167-
(cb) => remoteNodes[1].block.put(blocks[2], cb),
168-
(cb) => remoteNodes[1].block.put(blocks[3], cb),
169-
(cb) => inProcNode.block.put(blocks[4], cb),
170-
(cb) => inProcNode.block.put(blocks[5], cb),
171-
// 3. Fetch blocks on all nodes
172-
(cb) => parallel(_.range(6).map((i) => (cbI) => {
173-
const check = (n, cid, callback) => {
174-
n.block.get(cid, (err, b) => {
175-
expect(err).to.not.exist()
176-
expect(b).to.eql(blocks[i])
177-
callback()
178-
})
179-
}
180-
181-
series([
182-
(cbJ) => check(remoteNodes[0], blocks[i].cid, cbJ),
183-
(cbJ) => check(remoteNodes[1], blocks[i].cid, cbJ),
184-
(cbJ) => check(inProcNode, blocks[i].cid, cbJ)
185-
], cbI)
186-
}), cb)
187-
], done)
188-
})
179+
series([
180+
(cbJ) => check(remoteNodes[0], blocks[i].cid, cbJ),
181+
(cbJ) => check(remoteNodes[1], blocks[i].cid, cbJ),
182+
(cbJ) => check(inProcNode, blocks[i].cid, cbJ)
183+
], cbI)
184+
}), cb)
185+
], done)
189186
})
187+
})
190188

191-
describe('fetches a remote file', () => {
192-
it('2 peers', (done) => {
193-
const file = Buffer.from(`I love IPFS <3 ${Math.random()}`)
194-
195-
waterfall([
196-
// 0. Start node
197-
(cb) => addNode(12, cb),
198-
// 1. Add file to tmp instance
199-
(remote, cb) => {
200-
remote.files.add([{path: 'awesome.txt', content: file}], cb)
201-
},
202-
// 2. Request file from local instance
203-
(filesAdded, cb) => inProcNode.files.cat(filesAdded[0].hash, cb)
204-
], (err, data) => {
205-
expect(err).to.not.exist()
206-
expect(data).to.eql(file)
207-
done()
208-
})
189+
describe('transfer a file between', () => {
190+
it('2 peers', (done) => {
191+
// TODO make this test more interesting (10Mb file)
192+
const file = Buffer.from(`I love IPFS <3 ${Math.random()}`)
193+
194+
waterfall([
195+
// 0. Start node
196+
(cb) => addNode(12, inProcNode, cb),
197+
// 1. Add file to tmp instance
198+
(remote, cb) => {
199+
remote.files.add([{path: 'awesome.txt', content: file}], cb)
200+
},
201+
// 2. Request file from local instance
202+
(filesAdded, cb) => inProcNode.files.cat(filesAdded[0].hash, cb)
203+
], (err, data) => {
204+
expect(err).to.not.exist()
205+
expect(data).to.eql(file)
206+
done()
209207
})
210208
})
211209
})
212210

213-
describe('bitswap API', () => {
211+
describe('api', () => {
214212
let node
215213

216214
before(function (done) {
@@ -243,8 +241,7 @@ describe('bitswap', function () {
243241
})
244242

245243
it('throws if offline', () => {
246-
expect(() => node.bitswap.unwant('my key'))
247-
.to.throw(/online/)
244+
expect(() => node.bitswap.unwant('my key')).to.throw(/online/)
248245
})
249246
})
250247

‎test/core/bootstrap.spec.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ describe('bootstrap', () => {
1818

1919
let node
2020

21-
before((done) => {
21+
before(function (done) {
22+
this.timeout(40 * 1000)
2223
node = new IPFS({
2324
repo: createTempRepo(),
2425
init: {

‎test/core/create-node.spec.js

+15-20
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,8 @@ const IPFS = require('../../src/core')
1515
const createTempRepo = require('../utils/create-repo-nodejs.js')
1616

1717
describe('create node', function () {
18-
this.timeout(40 * 1000)
19-
2018
it('custom repoPath', function (done) {
21-
this.timeout(40 * 1000)
19+
this.timeout(80 * 1000)
2220

2321
const node = new IPFS({
2422
repo: '/tmp/ipfs-repo-' + Math.random(),
@@ -43,7 +41,7 @@ describe('create node', function () {
4341
})
4442

4543
it('custom repo', function (done) {
46-
this.timeout(40 * 1000)
44+
this.timeout(80 * 1000)
4745

4846
const node = new IPFS({
4947
repo: createTempRepo(),
@@ -67,7 +65,7 @@ describe('create node', function () {
6765
})
6866

6967
it('IPFS.createNode', function (done) {
70-
this.timeout(40 * 1000)
68+
this.timeout(80 * 1000)
7169

7270
const node = IPFS.createNode({
7371
repo: createTempRepo(),
@@ -94,12 +92,12 @@ describe('create node', function () {
9492
})
9593

9694
it('init: { bits: 1024 }', function (done) {
97-
this.timeout(40 * 1000)
95+
this.timeout(80 * 1000)
9896

9997
const node = new IPFS({
10098
repo: createTempRepo(),
10199
init: {
102-
bits: 1024
100+
bits: 512
103101
},
104102
config: {
105103
Addresses: {
@@ -121,7 +119,7 @@ describe('create node', function () {
121119
})
122120

123121
it('init: false errors (start default: true)', function (done) {
124-
this.timeout(40 * 1000)
122+
this.timeout(80 * 1000)
125123

126124
const node = new IPFS({
127125
repo: createTempRepo(),
@@ -139,7 +137,7 @@ describe('create node', function () {
139137
})
140138

141139
it('init: false, start: false', function (done) {
142-
this.timeout(40 * 1000)
140+
this.timeout(80 * 1000)
143141

144142
const node = new IPFS({
145143
repo: createTempRepo(),
@@ -169,7 +167,7 @@ describe('create node', function () {
169167
})
170168

171169
it('init: true, start: false', function (done) {
172-
this.timeout(40 * 1000)
170+
this.timeout(80 * 1000)
173171

174172
const node = new IPFS({
175173
repo: createTempRepo(),
@@ -191,7 +189,7 @@ describe('create node', function () {
191189
})
192190

193191
it('init: true, start: false, use callback', function (done) {
194-
this.timeout(40 * 1000)
192+
this.timeout(80 * 1000)
195193

196194
const node = new IPFS({
197195
repo: createTempRepo(),
@@ -210,7 +208,7 @@ describe('create node', function () {
210208
})
211209

212210
it('overload config', function (done) {
213-
this.timeout(40 * 1000)
211+
this.timeout(80 * 1000)
214212

215213
if (!isNode) { return done() }
216214

@@ -229,10 +227,7 @@ describe('create node', function () {
229227
node.config.get((err, config) => {
230228
expect(err).to.not.exist()
231229

232-
expect(config.Addresses.Swarm).to.eql(
233-
['/ip4/127.0.0.1/tcp/9977']
234-
)
235-
230+
expect(config.Addresses.Swarm).to.eql(['/ip4/127.0.0.1/tcp/9977'])
236231
expect(config.Bootstrap).to.eql([])
237232

238233
node.stop(done)
@@ -241,7 +236,7 @@ describe('create node', function () {
241236
})
242237

243238
it('start and stop, start and stop', function (done) {
244-
this.timeout(40 * 1000)
239+
this.timeout(80 * 1000)
245240

246241
const node = new IPFS({
247242
repo: createTempRepo(),
@@ -262,7 +257,7 @@ describe('create node', function () {
262257
})
263258

264259
it('stop as promised', function (done) {
265-
this.timeout(40 * 1000)
260+
this.timeout(80 * 1000)
266261

267262
const node = new IPFS({
268263
repo: createTempRepo(),
@@ -282,7 +277,7 @@ describe('create node', function () {
282277
})
283278

284279
it('can start node twice without crash', function (done) {
285-
this.timeout(40 * 1000)
280+
this.timeout(80 * 1000)
286281

287282
const options = {
288283
repo: createTempRepo(),
@@ -301,7 +296,7 @@ describe('create node', function () {
301296
(cb) => node.stop(cb),
302297
(cb) => {
303298
node = new IPFS(options)
304-
node.on('error', cb)
299+
node.once('error', cb)
305300
node.once('start', cb)
306301
},
307302
(cb) => node.stop(cb)

‎test/gateway/index.js

+117-120
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const API = require('../../src/http')
1010
const loadFixture = require('aegir/fixtures')
1111
const os = require('os')
1212
const path = require('path')
13+
const hat = require('hat')
1314
const fileType = require('file-type')
1415

1516
const bigFile = loadFixture(__dirname, '../../node_modules/interface-ipfs-core/test/fixtures/15mb.random', 'ipfs')
@@ -21,16 +22,15 @@ const directoryContent = {
2122
'cat-folder/cat.jpg': loadFixture(__dirname, './test-folder/cat-folder/cat.jpg', 'ipfs')
2223
}
2324

24-
describe('HTTP Gateway', () => {
25+
describe('HTTP Gateway', function () {
26+
this.timeout(80 * 1000)
27+
2528
let http = {}
2629
let gateway
2730

2831
before(function (done) {
29-
this.timeout(20 * 1000)
30-
const repoPath = path.join(
31-
os.tmpdir(),
32-
'/ipfs-' + Math.random().toString().substring(2, 8) + '-' + Date.now()
33-
)
32+
this.timeout(60 * 1000)
33+
const repoPath = path.join(os.tmpdir(), '/ipfs-' + hat())
3434

3535
http.api = new API(repoPath, {
3636
Bootstrap: [],
@@ -114,141 +114,138 @@ describe('HTTP Gateway', () => {
114114

115115
after((done) => http.api.stop(done))
116116

117-
describe('## HTTP Gateway', function () {
118-
this.timeout(20 * 1000)
119-
it('returns 400 for request without argument', (done) => {
120-
gateway.inject({
121-
method: 'GET',
122-
url: '/ipfs'
123-
}, (res) => {
124-
expect(res.statusCode).to.equal(400)
125-
expect(res.result.Message).to.be.a('string')
126-
done()
127-
})
117+
it('returns 400 for request without argument', (done) => {
118+
gateway.inject({
119+
method: 'GET',
120+
url: '/ipfs'
121+
}, (res) => {
122+
expect(res.statusCode).to.equal(400)
123+
expect(res.result.Message).to.be.a('string')
124+
done()
128125
})
126+
})
129127

130-
it('400 for request with invalid argument', (done) => {
131-
gateway.inject({
132-
method: 'GET',
133-
url: '/ipfs/invalid'
134-
}, (res) => {
135-
expect(res.statusCode).to.equal(400)
136-
expect(res.result.Message).to.be.a('string')
137-
done()
138-
})
128+
it('400 for request with invalid argument', (done) => {
129+
gateway.inject({
130+
method: 'GET',
131+
url: '/ipfs/invalid'
132+
}, (res) => {
133+
expect(res.statusCode).to.equal(400)
134+
expect(res.result.Message).to.be.a('string')
135+
done()
139136
})
137+
})
140138

141-
it('valid hash', (done) => {
142-
gateway.inject({
143-
method: 'GET',
144-
url: '/ipfs/QmT78zSuBmuS4z925WZfrqQ1qHaJ56DQaTfyMUF7F8ff5o'
145-
}, (res) => {
146-
expect(res.statusCode).to.equal(200)
147-
expect(res.rawPayload).to.eql(Buffer.from('hello world' + '\n'))
148-
expect(res.payload).to.equal('hello world' + '\n')
149-
done()
150-
})
139+
it('valid hash', (done) => {
140+
gateway.inject({
141+
method: 'GET',
142+
url: '/ipfs/QmT78zSuBmuS4z925WZfrqQ1qHaJ56DQaTfyMUF7F8ff5o'
143+
}, (res) => {
144+
expect(res.statusCode).to.equal(200)
145+
expect(res.rawPayload).to.eql(Buffer.from('hello world' + '\n'))
146+
expect(res.payload).to.equal('hello world' + '\n')
147+
done()
151148
})
149+
})
152150

153-
it('stream a large file', (done) => {
154-
let bigFileHash = 'Qme79tX2bViL26vNjPsF3DP1R9rMKMvnPYJiKTTKPrXJjq'
155-
156-
gateway.inject({
157-
method: 'GET',
158-
url: '/ipfs/' + bigFileHash
159-
}, (res) => {
160-
expect(res.statusCode).to.equal(200)
161-
expect(res.rawPayload).to.eql(bigFile)
162-
done()
163-
})
151+
it('stream a large file', (done) => {
152+
let bigFileHash = 'Qme79tX2bViL26vNjPsF3DP1R9rMKMvnPYJiKTTKPrXJjq'
153+
154+
gateway.inject({
155+
method: 'GET',
156+
url: '/ipfs/' + bigFileHash
157+
}, (res) => {
158+
expect(res.statusCode).to.equal(200)
159+
expect(res.rawPayload).to.eql(bigFile)
160+
done()
164161
})
162+
})
165163

166-
it('load a non text file', (done) => {
167-
let kitty = 'QmW2WQi7j6c7UgJTarActp7tDNikE4B2qXtFCfLPdsgaTQ/cat.jpg'
164+
it('load a non text file', (done) => {
165+
let kitty = 'QmW2WQi7j6c7UgJTarActp7tDNikE4B2qXtFCfLPdsgaTQ/cat.jpg'
168166

169-
gateway.inject({
170-
method: 'GET',
171-
url: '/ipfs/' + kitty
172-
}, (res) => {
173-
expect(res.statusCode).to.equal(200)
174-
expect(res.headers['content-type']).to.equal('image/jpeg')
167+
gateway.inject({
168+
method: 'GET',
169+
url: '/ipfs/' + kitty
170+
}, (res) => {
171+
expect(res.statusCode).to.equal(200)
172+
expect(res.headers['content-type']).to.equal('image/jpeg')
175173

176-
let fileSignature = fileType(res.rawPayload)
177-
expect(fileSignature.mime).to.equal('image/jpeg')
178-
expect(fileSignature.ext).to.equal('jpg')
174+
let fileSignature = fileType(res.rawPayload)
175+
expect(fileSignature.mime).to.equal('image/jpeg')
176+
expect(fileSignature.ext).to.equal('jpg')
179177

180-
done()
181-
})
178+
done()
182179
})
180+
})
183181

184-
it('load a directory', (done) => {
185-
let dir = 'QmW2WQi7j6c7UgJTarActp7tDNikE4B2qXtFCfLPdsgaTQ/'
186-
187-
gateway.inject({
188-
method: 'GET',
189-
url: '/ipfs/' + dir
190-
}, (res) => {
191-
expect(res.statusCode).to.equal(200)
192-
expect(res.headers['content-type']).to.equal('text/html; charset=utf-8')
193-
194-
// check if the cat picture is in the payload as a way to check
195-
// if this is an index of this directory
196-
let listedFile = res.payload.match(/\/ipfs\/QmW2WQi7j6c7UgJTarActp7tDNikE4B2qXtFCfLPdsgaTQ\/cat\.jpg/g)
197-
expect(listedFile).to.have.lengthOf(1)
198-
done()
199-
})
182+
it('load a directory', (done) => {
183+
let dir = 'QmW2WQi7j6c7UgJTarActp7tDNikE4B2qXtFCfLPdsgaTQ/'
184+
185+
gateway.inject({
186+
method: 'GET',
187+
url: '/ipfs/' + dir
188+
}, (res) => {
189+
expect(res.statusCode).to.equal(200)
190+
expect(res.headers['content-type']).to.equal('text/html; charset=utf-8')
191+
192+
// check if the cat picture is in the payload as a way to check
193+
// if this is an index of this directory
194+
let listedFile = res.payload.match(/\/ipfs\/QmW2WQi7j6c7UgJTarActp7tDNikE4B2qXtFCfLPdsgaTQ\/cat\.jpg/g)
195+
expect(listedFile).to.have.lengthOf(1)
196+
done()
200197
})
198+
})
201199

202-
it('load a webpage index.html', (done) => {
203-
let dir = 'QmbQD7EMEL1zeebwBsWEfA3ndgSS6F7S6iTuwuqasPgVRi/index.html'
204-
205-
gateway.inject({
206-
method: 'GET',
207-
url: '/ipfs/' + dir
208-
}, (res) => {
209-
expect(res.statusCode).to.equal(200)
210-
expect(res.rawPayload).to.deep.equal(directoryContent['index.html'])
211-
done()
212-
})
200+
it('load a webpage index.html', (done) => {
201+
let dir = 'QmbQD7EMEL1zeebwBsWEfA3ndgSS6F7S6iTuwuqasPgVRi/index.html'
202+
203+
gateway.inject({
204+
method: 'GET',
205+
url: '/ipfs/' + dir
206+
}, (res) => {
207+
expect(res.statusCode).to.equal(200)
208+
expect(res.rawPayload).to.deep.equal(directoryContent['index.html'])
209+
done()
213210
})
211+
})
214212

215-
it('load a webpage {hash}/nested-folder/nested.html', (done) => {
216-
let dir = 'QmbQD7EMEL1zeebwBsWEfA3ndgSS6F7S6iTuwuqasPgVRi/nested-folder/nested.html'
217-
218-
gateway.inject({
219-
method: 'GET',
220-
url: '/ipfs/' + dir
221-
}, (res) => {
222-
expect(res.statusCode).to.equal(200)
223-
expect(res.rawPayload).to.deep.equal(directoryContent['nested-folder/nested.html'])
224-
done()
225-
})
213+
it('load a webpage {hash}/nested-folder/nested.html', (done) => {
214+
let dir = 'QmbQD7EMEL1zeebwBsWEfA3ndgSS6F7S6iTuwuqasPgVRi/nested-folder/nested.html'
215+
216+
gateway.inject({
217+
method: 'GET',
218+
url: '/ipfs/' + dir
219+
}, (res) => {
220+
expect(res.statusCode).to.equal(200)
221+
expect(res.rawPayload).to.deep.equal(directoryContent['nested-folder/nested.html'])
222+
done()
226223
})
224+
})
227225

228-
it('redirect to generated index', (done) => {
229-
let dir = 'QmW2WQi7j6c7UgJTarActp7tDNikE4B2qXtFCfLPdsgaTQ'
230-
231-
gateway.inject({
232-
method: 'GET',
233-
url: '/ipfs/' + dir
234-
}, (res) => {
235-
expect(res.statusCode).to.equal(301)
236-
expect(res.headers['location']).to.equal('/ipfs/QmW2WQi7j6c7UgJTarActp7tDNikE4B2qXtFCfLPdsgaTQ/')
237-
done()
238-
})
226+
it('redirect to generated index', (done) => {
227+
let dir = 'QmW2WQi7j6c7UgJTarActp7tDNikE4B2qXtFCfLPdsgaTQ'
228+
229+
gateway.inject({
230+
method: 'GET',
231+
url: '/ipfs/' + dir
232+
}, (res) => {
233+
expect(res.statusCode).to.equal(301)
234+
expect(res.headers['location']).to.equal('/ipfs/QmW2WQi7j6c7UgJTarActp7tDNikE4B2qXtFCfLPdsgaTQ/')
235+
done()
239236
})
237+
})
238+
239+
it('redirect to webpage index.html', (done) => {
240+
let dir = 'QmbQD7EMEL1zeebwBsWEfA3ndgSS6F7S6iTuwuqasPgVRi/'
240241

241-
it('redirect to webpage index.html', (done) => {
242-
let dir = 'QmbQD7EMEL1zeebwBsWEfA3ndgSS6F7S6iTuwuqasPgVRi/'
243-
244-
gateway.inject({
245-
method: 'GET',
246-
url: '/ipfs/' + dir
247-
}, (res) => {
248-
expect(res.statusCode).to.equal(302)
249-
expect(res.headers['location']).to.equal('/ipfs/QmbQD7EMEL1zeebwBsWEfA3ndgSS6F7S6iTuwuqasPgVRi/index.html')
250-
done()
251-
})
242+
gateway.inject({
243+
method: 'GET',
244+
url: '/ipfs/' + dir
245+
}, (res) => {
246+
expect(res.statusCode).to.equal(302)
247+
expect(res.headers['location']).to.equal('/ipfs/QmbQD7EMEL1zeebwBsWEfA3ndgSS6F7S6iTuwuqasPgVRi/index.html')
248+
done()
252249
})
253250
})
254251
})

‎test/http-api/extra/bootstrap.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ module.exports = (ctl) => {
1212
const validIp4 = '/ip4/101.236.176.52/tcp/4001/ipfs/QmSoLnSGccFuZQJzRadHn95W2CrSFmZuTdDWP8HXaHca9z'
1313
let peers
1414

15-
describe('.add', () => {
15+
describe('.add', function () {
16+
this.timeout(40 * 1000)
17+
1618
it('returns an error when called with an invalid arg', (done) => {
1719
ctl.bootstrap.add(invalidArg, (err) => {
1820
expect(err).to.be.an.instanceof(Error)

‎test/http-api/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ describe('HTTP API', () => {
1919
let http = {}
2020

2121
before(function (done) {
22-
this.timeout(40 * 1000)
22+
this.timeout(60 * 1000)
2323

2424
const options = { enablePubsubExperiment: true }
2525
http.api = new API(repoTests, null, options)

‎test/utils/on-and-off.js

+7-5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
'use strict'
33

44
const Factory = require('../utils/ipfs-factory-daemon')
5+
const hat = require('hat')
56
const chai = require('chai')
67
const dirtyChai = require('dirty-chai')
78
const expect = chai.expect
@@ -17,15 +18,16 @@ function off (tests) {
1718
let repoPath
1819

1920
before(function () {
20-
this.timeout(30 * 1000)
21-
repoPath = os.tmpdir() + '/ipfs-' + Math.random().toString().substring(2, 16)
21+
this.timeout(60 * 1000)
22+
23+
repoPath = os.tmpdir() + '/ipfs-' + hat()
2224
thing.ipfs = ipfsExec(repoPath)
2325
thing.ipfs.repoPath = repoPath
2426
return thing.ipfs('init')
2527
})
2628

2729
after(function (done) {
28-
this.timeout(20 * 1000)
30+
this.timeout(26 * 1000)
2931
clean(repoPath)
3032
setImmediate(done)
3133
})
@@ -43,7 +45,7 @@ function on (tests) {
4345
// CI takes longer to instantiate the daemon,
4446
// so we need to increase the timeout for the
4547
// before step
46-
this.timeout(30 * 1000)
48+
this.timeout(60 * 1000)
4749

4850
factory = new Factory()
4951

@@ -56,7 +58,7 @@ function on (tests) {
5658
})
5759

5860
after(function (done) {
59-
this.timeout(20 * 1000)
61+
this.timeout(60 * 1000)
6062
factory.dismantle(done)
6163
})
6264

0 commit comments

Comments
 (0)
This repository has been archived.