Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: make sure repo is being properly cleaned up #196

Merged
merged 5 commits into from
Feb 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,14 @@
"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",
"superagent": "^3.8.2",
"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",
Expand Down
11 changes: 6 additions & 5 deletions src/daemon-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -142,10 +141,6 @@ class Node {
callback(null, this)
})
})

if (this.disposable) {
shutdown.addHandler('disposable', 1, this.cleanup.bind(this))
}
}

/**
Expand All @@ -161,6 +156,7 @@ class Node {
return callback()
}

this.clean = true
rimraf(this.path, callback)
}

Expand Down Expand Up @@ -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()
})

Expand Down
1 change: 1 addition & 0 deletions src/in-proc-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ class Node {
}

this.initialized = true
this.clean = false
callback(null, this)
})
})
Expand Down
8 changes: 4 additions & 4 deletions test/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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')
Expand Down
6 changes: 6 additions & 0 deletions test/daemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')()
})
Expand Down
3 changes: 2 additions & 1 deletion test/spawning.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
}

Expand Down
20 changes: 16 additions & 4 deletions test/start-stop.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ module.exports = (type) => {
}

let ipfsd
let repoPath

describe(`create and init a node (ipfsd)`, function () {
this.timeout(50 * 1000)
Expand All @@ -37,6 +38,7 @@ module.exports = (type) => {
expect(daemon).to.exist()

ipfsd = daemon
repoPath = ipfsd.path
done()
})
})
Expand Down Expand Up @@ -88,7 +90,6 @@ module.exports = (type) => {

describe('stopping', () => {
let stopped = false

before(function (done) {
this.timeout(20 * 1000)
ipfsd.stop((err) => {
Expand Down Expand Up @@ -116,6 +117,10 @@ module.exports = (type) => {
done()
})
})

it('repo should cleaned up', () => {
expect(fs.existsSync(repoPath)).to.not.be.ok()
})
})
})

Expand Down Expand Up @@ -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()
Expand Down