Skip to content

Commit

Permalink
FIX abort reason
Browse files Browse the repository at this point in the history
  • Loading branch information
pubkey committed Mar 23, 2023
1 parent 2311480 commit f3a86a2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/leader-election-web-lock.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
16 changes: 16 additions & 0 deletions test/integration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down

0 comments on commit f3a86a2

Please sign in to comment.