X-Git-Url: https://git.squeep.com/?a=blobdiff_plain;f=test%2Fsrc%2Fworker.js;h=6e1315893f954b17b6eb37233620f977cceacee9;hb=71587de3ea9839d14d9f7bffa6c1db19e52dd9b5;hp=32bd0656665bd854933240eb5323a440e1e438c5;hpb=9f9d3c81cc0960f03e6598258d36ad828058f65f;p=websub-hub diff --git a/test/src/worker.js b/test/src/worker.js index 32bd065..6e13158 100644 --- a/test/src/worker.js +++ b/test/src/worker.js @@ -131,6 +131,12 @@ describe('Worker', function () { stubCtx = {}; }); it('gets tasks', async function () { + /** + * In older versions, could just deepStrictEqual un-awaited promises for equality, + * but post 14 or so, async_id symbol properties are included in comparison, and + * in some executions of test suites these are somehow different in value so the test + * was failing. So now we settle everything prior to comparison. + */ const expected = [ Promise.resolve('first'), Promise.reject('bad'), @@ -138,7 +144,11 @@ describe('Worker', function () { ]; worker.promiseGiver.resolves(expected); const result = await worker._getWork(stubCtx); - assert.deepStrictEqual(result, expected); + + const expectedResolved = await Promise.allSettled(expected); + const resultResolved = await Promise.allSettled(result); + assert.deepStrictEqual(resultResolved, expectedResolved); + assert.strictEqual(worker.inFlight.length, expected.length); }); it('covers none wanted', async function () { @@ -204,6 +214,18 @@ describe('Worker', function () { assert.strictEqual(worker._getWork.callCount, 0); assert.strictEqual(worker._recurr.callCount, 1); }); + it('covers double invocation', async function () { + const snooze = async (ms) => new Promise((resolve) => setTimeout(resolve, ms)); + + this.slow(300); + worker.inFlight = [ + Worker.watchedPromise(snooze(100)), + ]; + + await Promise.all([worker.process(), worker.process()]); + assert.strictEqual(worker._getWork.callCount, 2); + assert.strictEqual(worker._recurr.callCount, 1); + }); }); // process }); // Worker