diff --git a/src/ipfsd-client.js b/src/ipfsd-client.js index 004ef50e..c63e2d97 100644 --- a/src/ipfsd-client.js +++ b/src/ipfsd-client.js @@ -148,20 +148,21 @@ class DaemonClient { /** * Stop the daemon. * - * @param {integer} - Grace period to wait before force stopping the node + * @param {integer|undefined} timeout - Grace period to wait before force stopping the node * @param {function(Error)} [cb] * @returns {undefined} */ stop (timeout, cb) { if (typeof timeout === 'function') { cb = timeout - timeout = null + timeout = undefined } cb = cb || (() => {}) request .post(`${this.baseUrl}/stop`) - .query({ id: this._id, timeout }) + .query({ id: this._id }) + .send({ timeout }) .end((err) => { if (err) { return cb(new Error(err.response.body.message)) @@ -178,20 +179,21 @@ class DaemonClient { * First `SIGTERM` is sent, after 10.5 seconds `SIGKILL` is sent * if the process hasn't exited yet. * - * @param {integer} - Grace period to wait before force stopping the node + * @param {integer|undefined} timeout - Grace period to wait before force stopping the node * @param {function()} [cb] - Called when the process was killed. * @returns {undefined} */ killProcess (timeout, cb) { if (typeof timeout === 'function') { cb = timeout - timeout = null + timeout = undefined } cb = cb || (() => {}) request .post(`${this.baseUrl}/kill`) - .query({ id: this._id, timeout }) + .query({ id: this._id }) + .send({ timeout }) .end((err) => { if (err) { return cb(new Error(err.response.body.message)) diff --git a/src/ipfsd-daemon.js b/src/ipfsd-daemon.js index a37d0536..e00ba989 100644 --- a/src/ipfsd-daemon.js +++ b/src/ipfsd-daemon.js @@ -288,7 +288,7 @@ class Daemon { /** * Stop the daemon. * - * @param {integer} - Grace period to wait before force stopping the node + * @param {integer|undefined} timeout - Grace period to wait before force stopping the node * @param {function(Error)} callback * @returns {undefined} */ @@ -314,7 +314,7 @@ class Daemon { * process.kill(`SIGTERM`) is used. In either case, if the process * does not exit after 10.5 seconds then a `SIGKILL` is used. * - * @param {integer} - Grace period to wait before force stopping the node + * @param {integer|undefined} timeout - Grace period to wait before force stopping the node * @param {function()} callback - Called when the process was killed. * @returns {undefined} */ diff --git a/test/endpoint/routes.js b/test/endpoint/routes.js index f7646111..a51c817c 100644 --- a/test/endpoint/routes.js +++ b/test/endpoint/routes.js @@ -213,7 +213,19 @@ describe('routes', () => { }) describe('POST /stop', () => { - it('should return 200', (done) => { + it('should return 200 without timeout', (done) => { + server.inject({ + method: 'POST', + url: `/stop?id=${id}`, + headers: { 'content-type': 'application/json' }, + payload: { id } + }, (res) => { + expect(res.statusCode).to.equal(200) + done() + }) + }) + + it('should return 200 with timeout', (done) => { server.inject({ method: 'POST', url: `/stop?id=${id}`, @@ -250,6 +262,18 @@ describe('routes', () => { }) }) + it('should return 200 with timeout', (done) => { + server.inject({ + method: 'POST', + url: `/kill?id=${id}`, + headers: { 'content-type': 'application/json' }, + payload: { id, timeout: 1000 } + }, (res) => { + expect(res.statusCode).to.equal(200) + done() + }) + }) + it('should return 400', (done) => { server.inject({ method: 'POST', diff --git a/test/start-stop.node.js b/test/start-stop.node.js index a19db8c3..8aab5209 100644 --- a/test/start-stop.node.js +++ b/test/start-stop.node.js @@ -230,12 +230,11 @@ tests.forEach((fOpts) => { }) }) - it('.stop with timeout', function (done) { - this.timeout(15000) // should not take longer than timeout + this.timeout(15000 + 10) // should not take longer than timeout ipfsd.stop(15000, (err) => { expect(err).to.not.exist() - const running = isrunning(pid) + expect(isrunning(pid)).to.not.be.ok() done() }) })