diff --git a/test/asyncprogressqueueworker.cc b/test/asyncprogressqueueworker.cc index b30863301..bb2efb017 100644 --- a/test/asyncprogressqueueworker.cc +++ b/test/asyncprogressqueueworker.cc @@ -40,8 +40,6 @@ class TestWorker : public AsyncProgressQueueWorker { static void CancelWork(const CallbackInfo& info) { auto wrap = info[0].As>(); auto worker = wrap.Data(); - // We cannot cancel a worker if it got started. So we have to do a quick cancel. - worker->Queue(); worker->Cancel(); } diff --git a/test/asyncprogressqueueworker.js b/test/asyncprogressqueueworker.js index 4ad8c43d5..4eb800c36 100644 --- a/test/asyncprogressqueueworker.js +++ b/test/asyncprogressqueueworker.js @@ -10,7 +10,7 @@ module.exports = test(require(`./build/${buildType}/binding.node`)) async function test({ asyncprogressqueueworker }) { await success(asyncprogressqueueworker); await fail(asyncprogressqueueworker); - await cancel(asyncprogressqueueworker); + cancel(asyncprogressqueueworker); } function success(binding) { @@ -49,22 +49,17 @@ function fail(binding) { } function cancel(binding) { - return new Promise((resolve, reject) => { - // make sure the work we are going to cancel will not be - // able to start by using all the threads in the pool. - for (let i = 0; i < os.cpus().length; ++i) { - const worker = binding.createWork(-1, () => {}, () => {}); - binding.queueWork(worker); - } - const worker = binding.createWork(-1, - () => { - assert.fail('unexpected callback'); - }, - () => { - assert.fail('unexpected progress report'); - } - ); - binding.cancelWork(worker); - resolve(); - }); + // We cannot cancel work once it gets started, so we have no choice here but + // to create the work and then cancel it without queueing it. Thus we cannot + // reliably test create -> queue -> cancel. + // + // We could queue it and immediately cancel, and we could even attempt to + // saturate the thread pool with work before we do that but that would still + // be racy and, on some platforms and under certain circumstances the work + // might still get queued and therefore be unable to be cancelled, resulting + // in this test being flaky. + const worker = binding.createWork(-1, + () => reject(new Error('unexpected callback')), + () => reject(new Error('unexpected progress report'))); + binding.cancelWork(worker); }