mirror of
https://github.com/signalapp/Signal-Desktop.git
synced 2026-04-23 01:48:13 +01:00
Faster WebSocket reconnects
This commit is contained in:
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);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user