forked from zulip/zulip-mobile
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
makeBackoffMachine: Add, for replacement of progressiveTimeout.
Improve state logic for sleep durations in API request retry loops. progressiveTimeout used a global state, which had the benefit of enabling a general throttle affecting all request retry loops that used it. But different requests may have transient failures for different reasons, so per-request state handling makes more sense, and high request traffic is still mitigated by exponential backoff. Also, previously, any call to progressiveTimeout was nondeterministic, because other calls may have been done recently, affecting the delay duration. A 60-second threshold was used as a heuristic to distinguish request retry loops from each other, but this is more effectively done by managing the state per-loop in the first place, and the next sleep duration becomes a pure function of the number of sleeps completed. Preparation for zulip#3829.
- Loading branch information
Chris Bobbe
committed
Feb 5, 2020
1 parent
4724331
commit 1b17a8a
Showing
2 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* @flow strict-local */ | ||
import { makeBackoffMachine } from '../async'; | ||
|
||
describe('makeBackoffMachine', () => { | ||
test('timeouts are ~100ms, ~200ms, ~400ms, ~800ms', async () => { | ||
const backoffMachine = makeBackoffMachine(); | ||
|
||
const start0 = Date.now(); | ||
await backoffMachine.wait(); | ||
const duration0 = Date.now() - start0; | ||
expect(duration0).toBeGreaterThan(90); | ||
expect(duration0).toBeLessThan(110); | ||
|
||
const start1 = Date.now(); | ||
await backoffMachine.wait(); | ||
const duration1 = Date.now() - start1; | ||
expect(duration1).toBeGreaterThan(190); | ||
expect(duration1).toBeLessThan(210); | ||
|
||
const start2 = Date.now(); | ||
await backoffMachine.wait(); | ||
const duration2 = Date.now() - start2; | ||
expect(duration2).toBeGreaterThan(390); | ||
expect(duration2).toBeLessThan(410); | ||
|
||
const start3 = Date.now(); | ||
await backoffMachine.wait(); | ||
const duration3 = Date.now() - start3; | ||
expect(duration3).toBeGreaterThan(790); | ||
expect(duration3).toBeLessThan(810); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters