Retry outbound read syncs for up to 24 hours

This commit is contained in:
Evan Hahn 2021-07-23 17:02:36 -05:00 committed by GitHub
parent fc33e9be41
commit 18140c4a9d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 366 additions and 19 deletions

View file

@ -0,0 +1,46 @@
// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import { assert } from 'chai';
import * as moment from 'moment';
import {
exponentialBackoffSleepTime,
exponentialBackoffMaxAttempts,
} from '../../util/exponentialBackoff';
describe('exponential backoff utilities', () => {
describe('exponentialBackoffSleepTime', () => {
it('returns slowly growing values', () => {
assert.strictEqual(exponentialBackoffSleepTime(1), 0);
assert.strictEqual(exponentialBackoffSleepTime(2), 190);
assert.strictEqual(exponentialBackoffSleepTime(3), 361);
assert.approximately(exponentialBackoffSleepTime(4), 686, 1);
assert.approximately(exponentialBackoffSleepTime(5), 1303, 1);
});
it('plateaus at a maximum after 15 attempts', () => {
const maximum = moment.duration(15, 'minutes').asMilliseconds();
for (let attempt = 16; attempt < 100; attempt += 1) {
assert.strictEqual(exponentialBackoffSleepTime(attempt), maximum);
}
});
});
describe('exponentialBackoffMaxAttempts', () => {
it('returns 2 attempts for a short period of time', () => {
assert.strictEqual(exponentialBackoffMaxAttempts(1), 2);
assert.strictEqual(exponentialBackoffMaxAttempts(99), 2);
});
it('returns 6 attempts for a 5 seconds', () => {
assert.strictEqual(exponentialBackoffMaxAttempts(5000), 6);
});
it('returns 110 attempts for 1 day', () => {
// This is a test case that is lifted from iOS's codebase.
const oneDay = moment.duration(24, 'hours').asMilliseconds();
assert.strictEqual(exponentialBackoffMaxAttempts(oneDay), 110);
});
});
});