Optimize number of range requests in updater

This commit is contained in:
Fedor Indutny 2022-03-01 14:44:29 -08:00 committed by GitHub
parent 1a751c07fc
commit 19441cd3f3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 409 additions and 93 deletions

View file

@ -0,0 +1,40 @@
// Copyright 2022 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import { assert } from 'chai';
import { EventEmitter } from 'events';
import { wrapEventEmitterOnce as once } from '../../util/wrapEventEmitterOnce';
describe('wrapEventEmitterOnce', () => {
let ee: EventEmitter;
beforeEach(() => {
ee = new EventEmitter();
});
it('should get the event arguments', async () => {
const result = once(ee, 'result');
ee.emit('result', 1, 2, 3);
assert.deepStrictEqual(await result, [1, 2, 3]);
});
it('should handle error event', async () => {
const result = once(ee, 'result');
ee.emit('error', new Error('aha!'));
await assert.isRejected(result, 'aha!');
});
it('should stop handling error event after result', async () => {
const result = once(ee, 'result');
ee.emit('result', 'okay');
assert.deepStrictEqual(await result, ['okay']);
assert.strictEqual(ee.listeners('error').length, 0);
});
});