Faster WebSocket reconnects
This commit is contained in:
parent
3cac4a19e1
commit
17e6ec468e
25 changed files with 940 additions and 677 deletions
45
ts/test-both/util/BackOff_test.ts
Normal file
45
ts/test-both/util/BackOff_test.ts
Normal file
|
@ -0,0 +1,45 @@
|
|||
// Copyright 2021 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import { assert } from 'chai';
|
||||
|
||||
import { BackOff } from '../../util/BackOff';
|
||||
|
||||
describe('BackOff', () => {
|
||||
it('should return increasing timeouts', () => {
|
||||
const b = new BackOff([1, 2, 3]);
|
||||
|
||||
assert.strictEqual(b.getIndex(), 0);
|
||||
assert.strictEqual(b.isFull(), false);
|
||||
|
||||
assert.strictEqual(b.get(), 1);
|
||||
assert.strictEqual(b.getAndIncrement(), 1);
|
||||
assert.strictEqual(b.get(), 2);
|
||||
assert.strictEqual(b.getIndex(), 1);
|
||||
assert.strictEqual(b.isFull(), false);
|
||||
|
||||
assert.strictEqual(b.getAndIncrement(), 2);
|
||||
assert.strictEqual(b.getIndex(), 2);
|
||||
assert.strictEqual(b.isFull(), true);
|
||||
|
||||
assert.strictEqual(b.getAndIncrement(), 3);
|
||||
assert.strictEqual(b.getIndex(), 2);
|
||||
assert.strictEqual(b.isFull(), true);
|
||||
|
||||
assert.strictEqual(b.getAndIncrement(), 3);
|
||||
assert.strictEqual(b.getIndex(), 2);
|
||||
assert.strictEqual(b.isFull(), true);
|
||||
});
|
||||
|
||||
it('should reset', () => {
|
||||
const b = new BackOff([1, 2, 3]);
|
||||
|
||||
assert.strictEqual(b.getAndIncrement(), 1);
|
||||
assert.strictEqual(b.getAndIncrement(), 2);
|
||||
|
||||
b.reset();
|
||||
|
||||
assert.strictEqual(b.getAndIncrement(), 1);
|
||||
assert.strictEqual(b.getAndIncrement(), 2);
|
||||
});
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue