Skip to content

Commit b003584

Browse files
committed
fix: test & cleanup
1 parent 744c254 commit b003584

File tree

3 files changed

+43
-489
lines changed

3 files changed

+43
-489
lines changed

src/daemon.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const isWindows = os.platform() === 'win32'
1414

1515
const exec = require('./exec')
1616

17-
const GRACE_PERIOD = 7500 // amount of ms to wait before sigkill
17+
const GRACE_PERIOD = 10500 // amount of ms to wait before sigkill
1818

1919
function findIpfsExecutable (isJs, rootPath) {
2020
let appRoot = path.join(rootPath, '..')
@@ -91,11 +91,12 @@ class Node {
9191
*/
9292
constructor (path, opts, disposable) {
9393
const rootPath = process.env.testpath ? process.env.testpath : __dirname
94-
const isJS = process.env.IPFS_JS && process.env.IPFS_JS === 'true'
94+
const isJS = process.env.IPFS_JS && process.env.IPFS_JS === 'true' // TODO: handle proper truthy/falsy
95+
96+
this.opts = opts || { isJs: isJS || false }
97+
process.env.IPFS_JS = this.opts.isJs
9598

9699
this.path = path || null
97-
this.opts = opts || { isJs: false }
98-
this.isJs = this.opts.isJs || isJS || false
99100
this.exec = process.env.IPFS_EXEC || findIpfsExecutable(this.isJs, rootPath)
100101
this.subprocess = null
101102
this.initialized = fs.existsSync(path)
@@ -237,7 +238,7 @@ class Node {
237238
.filter(Boolean)
238239
.slice(-1)[0] || ''
239240

240-
if (input.match('daemon is running')) {
241+
if (input.match(/(?:daemon is running|Daemon is ready)/)) {
241242
// we're good
242243
return callback(null, this.api)
243244
}
@@ -254,7 +255,7 @@ class Node {
254255
: true
255256

256257
const gwMatch = want.gateway
257-
? output.trim().match(/Gateway (?:.*)? 27listening on[:]?(.*)/)
258+
? output.trim().match(/Gateway (?:.*) listening on[:]?(.*)/)
258259
: true
259260

260261
if (apiMatch && gwMatch && !returned) {
@@ -268,7 +269,7 @@ class Node {
268269
}
269270

270271
if (want.gateway) {
271-
this._gatewayAddr = multiaddr(gwMatch[2])
272+
this._gatewayAddr = multiaddr(gwMatch[1])
272273
this.api.gatewayHost = this.gatewayAddr.nodeAddress().address
273274
this.api.gatewayPort = this.gatewayAddr.nodeAddress().port
274275
}

test/spawning-go-daemons.spec.js renamed to test/spawning-daemons.spec.js

Lines changed: 35 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ const ipfsd = require('../src')
2020

2121
const isWindows = os.platform() === 'win32'
2222

23+
const VERSION_STRING = process.env.IPFS_JS ? 'js-ipfs version: 0.26.0' : 'ipfs version 0.4.11'
24+
const API_PORT = process.env.IPFS_JS ? '5002' : '5001'
25+
const GW_PORT = process.env.IPFS_JS ? '9090' : '8080'
26+
2327
describe('daemon spawning', () => {
2428
describe('local daemon', () => {
2529
const repoPath = '/tmp/ipfsd-ctl-test'
@@ -291,11 +295,15 @@ describe('daemon spawning', () => {
291295
})
292296
})
293297

294-
it('should give an error if setting an invalid config value', (done) => {
295-
ipfsNode.setConfig('Bootstrap', 'true', (err) => {
296-
expect(err.message).to.match(/failed to set config value/)
297-
done()
298-
})
298+
it('should give an error if setting an invalid config value', function (done) {
299+
if (!process.env.IPFS_JS) { // TODO: handle proper truthy/falsy
300+
ipfsNode.setConfig('Bootstrap', 'true', (err) => {
301+
expect(err.message).to.match(/failed to set config value/)
302+
done()
303+
})
304+
} else {
305+
this.skip()
306+
}
299307
})
300308
})
301309

@@ -313,7 +321,7 @@ describe('daemon spawning', () => {
313321
it('prints the version', (done) => {
314322
ipfsd.version((err, version) => {
315323
expect(err).to.not.exist()
316-
expect(version).to.be.eql('ipfs version 0.4.11')
324+
expect(version).to.be.eql(VERSION_STRING)
317325
done()
318326
})
319327
})
@@ -378,7 +386,8 @@ describe('daemon spawning', () => {
378386
})
379387

380388
describe('startDaemon', () => {
381-
it('start and stop', (done) => {
389+
it('start and stop', function (done) {
390+
this.timeout(20000)
382391
const dir = `${os.tmpdir()}/tmp-${Date.now() + '-' + Math.random().toString(36)}`
383392

384393
const check = (cb) => {
@@ -412,7 +421,9 @@ describe('daemon spawning', () => {
412421
], done)
413422
})
414423

415-
it('starts the daemon and returns valid API and gateway addresses', (done) => {
424+
it('starts the daemon and returns valid API and gateway addresses', function (done) {
425+
this.timeout(20000)
426+
416427
const dir = `${os.tmpdir()}/tmp-${Date.now() + '-' + Math.random().toString(36)}`
417428

418429
async.waterfall([
@@ -436,26 +447,30 @@ describe('daemon spawning', () => {
436447
expect(api).to.have.property('gatewayHost')
437448
expect(api).to.have.property('gatewayPort')
438449
expect(api.apiHost).to.equal('127.0.0.1')
439-
expect(api.apiPort).to.equal('5001')
450+
console.log(API_PORT)
451+
expect(api.apiPort).to.equal(API_PORT)
440452
expect(api.gatewayHost).to.equal('127.0.0.1')
441-
expect(api.gatewayPort).to.equal('8080')
453+
expect(api.gatewayPort).to.equal(GW_PORT)
442454

443455
daemon.stopDaemon(done)
444456
})
445457
})
446458

447-
it('allows passing flags', (done) => {
448-
ipfsd.disposable((err, node) => {
449-
expect(err).to.not.exist()
450-
451-
node.startDaemon(['--should-not-exist'], (err) => {
452-
expect(err).to.exist()
453-
expect(err.message)
454-
.to.match(/Unrecognized option 'should-not-exist'/)
459+
it('allows passing flags', function (done) {
460+
if (!process.env.IPFS_JS) {
461+
ipfsd.disposable((err, node) => {
462+
expect(err).to.not.exist()
463+
node.startDaemon(['--should-not-exist'], (err) => {
464+
expect(err).to.exist()
465+
expect(err.message)
466+
.to.match(/Unrecognized option 'should-not-exist'/)
455467

456-
done()
468+
done()
469+
})
457470
})
458-
})
471+
} else {
472+
this.skip()
473+
}
459474
})
460475
})
461476
})

0 commit comments

Comments
 (0)