diff --git a/package.json b/package.json index 5f103285..f99fdd39 100644 --- a/package.json +++ b/package.json @@ -79,7 +79,6 @@ "readable-stream": "^2.3.3", "rimraf": "^2.6.2", "safe-json-parse": "^4.0.0", - "shutdown": "^0.3.0", "ipfs-api": "^17.3.0", "stream-http": "^2.7.2", "subcomandante": "^1.0.5", @@ -87,7 +86,7 @@ "truthy": "0.0.1" }, "devDependencies": { - "aegir": "^12.2.0", + "aegir": "^12.4.0", "chai": "^4.1.2", "detect-port": "^1.2.2", "dirty-chai": "^2.0.1", diff --git a/src/daemon-node.js b/src/daemon-node.js index 2bcfed7a..2f35acd3 100644 --- a/src/daemon-node.js +++ b/src/daemon-node.js @@ -5,7 +5,6 @@ const async = require('async') const ipfs = require('ipfs-api') const multiaddr = require('multiaddr') const rimraf = require('rimraf') -const shutdown = require('shutdown') const path = require('path') const once = require('once') const truthy = require('truthy') @@ -142,10 +141,6 @@ class Node { callback(null, this) }) }) - - if (this.disposable) { - shutdown.addHandler('disposable', 1, this.cleanup.bind(this)) - } } /** @@ -161,6 +156,7 @@ class Node { return callback() } + this.clean = true rimraf(this.path, callback) } @@ -270,10 +266,15 @@ class Node { callback() }, GRACE_PERIOD) + const disposable = this.disposable + const clean = this.cleanup.bind(this) subprocess.once('close', () => { clearTimeout(timeout) this.subprocess = null this._started = false + if (disposable) { + return clean(callback) + } callback() }) diff --git a/src/in-proc-node.js b/src/in-proc-node.js index 2fad9557..0d92d145 100644 --- a/src/in-proc-node.js +++ b/src/in-proc-node.js @@ -141,6 +141,7 @@ class Node { } this.initialized = true + this.clean = false callback(null, this) }) }) diff --git a/test/api.js b/test/api.js index 2f58318b..eef02ee9 100644 --- a/test/api.js +++ b/test/api.js @@ -16,8 +16,8 @@ const isWindows = os.platform() === 'win32' module.exports = (df, type) => { return () => { - const API_PORT = type === 'js' ? '5002' : '5001' - const GW_PORT = type === 'js' ? '9090' : '8080' + const API_PORT = '5101' + const GW_PORT = '8180' const config = { Addresses: { @@ -93,9 +93,9 @@ module.exports = (df, type) => { describe('validate api', () => { it('starts the daemon and returns valid API and gateway addresses', function (done) { this.timeout(50 * 1000) - df.spawn({ config }, (err, res) => { + df.spawn({ config }, (err, _ipfsd) => { expect(err).to.not.exist() - const ipfsd = res + const ipfsd = _ipfsd // Check for props in daemon expect(ipfsd).to.have.property('apiAddr') diff --git a/test/daemon.js b/test/daemon.js index bfc79301..5b754049 100644 --- a/test/daemon.js +++ b/test/daemon.js @@ -21,6 +21,12 @@ describe('ipfsd-ctl', () => { api(df, 'go')() }) + describe('js daemon', () => { + const df = DaemonFactory.create({ type: 'js' }) + daemon(df, 'js')() + api(df, 'js')() + }) + describe('In-process daemon', () => { daemon(DaemonFactory.create({ remote: false, type: 'proc', exec: IPFS }), 'proc')() }) diff --git a/test/spawning.js b/test/spawning.js index 483b6367..2340adf4 100644 --- a/test/spawning.js +++ b/test/spawning.js @@ -192,7 +192,8 @@ module.exports = (df, type, exec) => { '/ip4/127.0.0.1/tcp/0/ws', '/ip4/127.0.0.1/tcp/0' ], - API: '/ip4/127.0.0.1/tcp/0' + API: '/ip4/127.0.0.1/tcp/0', + Gateway: '/ip4/127.0.0.1/tcp/0' } } diff --git a/test/start-stop.js b/test/start-stop.js index d7599a3f..bbda29d4 100644 --- a/test/start-stop.js +++ b/test/start-stop.js @@ -28,6 +28,7 @@ module.exports = (type) => { } let ipfsd + let repoPath describe(`create and init a node (ipfsd)`, function () { this.timeout(50 * 1000) @@ -37,6 +38,7 @@ module.exports = (type) => { expect(daemon).to.exist() ipfsd = daemon + repoPath = ipfsd.path done() }) }) @@ -88,7 +90,6 @@ module.exports = (type) => { describe('stopping', () => { let stopped = false - before(function (done) { this.timeout(20 * 1000) ipfsd.stop((err) => { @@ -116,6 +117,10 @@ module.exports = (type) => { done() }) }) + + it('repo should cleaned up', () => { + expect(fs.existsSync(repoPath)).to.not.be.ok() + }) }) }) @@ -181,10 +186,17 @@ module.exports = (type) => { before((done) => { async.series([ (cb) => df.spawn({ - init: false, - start: false, + init: true, + start: true, disposable: false, - repoPath: tempDir(type) + repoPath: tempDir(type), + config: { + Addresses: { + Swarm: [`/ip4/127.0.0.1/tcp/0`], + API: `/ip4/127.0.0.1/tcp/0`, + Gateway: `/ip4/127.0.0.1/tcp/0` + } + } }, (err, daemon) => { expect(err).to.not.exist() expect(daemon).to.exist()