Skip to content

Commit

Permalink
fix: properly timeout on worker termination (#395)
Browse files Browse the repository at this point in the history
  • Loading branch information
Michsior14 authored Aug 21, 2023
1 parent c16ae27 commit 066820f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/WorkerHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ WorkerHandler.prototype.terminate = function (force, callback) {
WorkerHandler.prototype.terminateAndNotify = function (force, timeout) {
var resolver = Promise.defer();
if (timeout) {
resolver.promise.timeout = timeout;
resolver.promise.timeout(timeout);
}
this.terminate(force, function(err, worker) {
if (err) {
Expand Down
28 changes: 28 additions & 0 deletions test/WorkerHandler.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -485,4 +485,32 @@ describe('WorkerHandler', function () {
});
});
});

describe('terminateAndNotify', function () {

it('promise should be resolved on termination', function (done) {
var handler = new WorkerHandler(__dirname + '/workers/async.js');

handler.terminateAndNotify(true)
.then(function () {
done();
}).catch(function (err) {
assert('Promise should not be rejected');
});
});

it('promise should be rejected if notify timeout is smaller than worker timeout', function (done) {
var handler = new WorkerHandler(__dirname + '/workers/async.js', {
workerTerminateTimeout: 100
});

handler.terminateAndNotify(true, 50)
.then(function () {
assert('Promise should not be resolved');
}).catch(function (err) {
assert.ok(err instanceof Promise.TimeoutError);
done();
});
});
});
});

0 comments on commit 066820f

Please sign in to comment.