From f3a86a2afb4297446243aed3207b32c7a88074db Mon Sep 17 00:00:00 2001 From: pubkey <8926560+pubkey@users.noreply.github.com> Date: Thu, 23 Mar 2023 14:13:20 +0100 Subject: [PATCH] FIX abort reason --- src/leader-election-web-lock.js | 2 +- test/integration.test.js | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/leader-election-web-lock.js b/src/leader-election-web-lock.js index fee50486..49bf8c89 100644 --- a/src/leader-election-web-lock.js +++ b/src/leader-election-web-lock.js @@ -84,7 +84,7 @@ LeaderElectionWebLock.prototype = { this._wKMC.res(); } if (this._wKMC.c) { - this._wKMC.c.abort(); + this._wKMC.c.abort('LeaderElectionWebLock.die() called'); } return ret; } diff --git a/test/integration.test.js b/test/integration.test.js index 8bd34d88..c64768eb 100644 --- a/test/integration.test.js +++ b/test/integration.test.js @@ -590,6 +590,22 @@ function runTest(channelOptions) { return unloadSizeAfter === unloadSizeBefore; }); }); + it('letting many die at the same time should not cause a problem', async () => { + const channelName = AsyncTestUtil.randomString(12); + const channels = new Array(20).fill(0).map(() => new BroadcastChannel(channelName, channelOptions)); + const leaderElectors = channels.map(c => { + const elector = createLeaderElection(c); + elector.awaitLeadership(); // trigger election + return elector; + }); + await AsyncTestUtil.wait(200); + await Promise.all( + leaderElectors.map(e => e.die()) + ); + await Promise.all( + channels.map(c => c.close()) + ); + }); }); describe('.awaitLeadership()', () => { it('should resolve when elector becomes leader', async () => {