mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-20 12:15:51 +00:00
* sets up linting config and runs `yarn lint --fix` once, so that all changes will show up correctly in future PRs. * Note that there are still a lot of linter errors.
39 lines
1.5 KiB
TypeScript
39 lines
1.5 KiB
TypeScript
import assert from "assert-diff";
|
|
|
|
import { ExponentialBackoff } from "../src/client/backoff";
|
|
|
|
describe("ExponentialBackoff", function () {
|
|
it("duration() return value starts with the min value", function () {
|
|
// default: 100ms
|
|
assert(new ExponentialBackoff().duration(), 100);
|
|
assert(new ExponentialBackoff({ min: 100 }).duration(), 100);
|
|
assert(new ExponentialBackoff({ min: 123 }).duration(), 123);
|
|
});
|
|
|
|
it("duration() return value increases when called multiple times", function () {
|
|
const backoff = new ExponentialBackoff({ min: 100, max: 1000 });
|
|
assert.strictEqual(backoff.duration(), 100);
|
|
assert.strictEqual(backoff.duration(), 200);
|
|
assert.strictEqual(backoff.duration(), 400);
|
|
assert.strictEqual(backoff.duration(), 800);
|
|
});
|
|
|
|
it("duration() never returns greater than the max value", function () {
|
|
const backoff = new ExponentialBackoff({ min: 300, max: 1000 });
|
|
assert.strictEqual(backoff.duration(), 300);
|
|
assert.strictEqual(backoff.duration(), 600);
|
|
assert.strictEqual(backoff.duration(), 1000);
|
|
assert.strictEqual(backoff.duration(), 1000);
|
|
});
|
|
|
|
it("reset() will reset the duration() value", function () {
|
|
const backoff = new ExponentialBackoff({ min: 100, max: 1000 });
|
|
assert.strictEqual(backoff.duration(), 100);
|
|
assert.strictEqual(backoff.duration(), 200);
|
|
assert.strictEqual(backoff.duration(), 400);
|
|
backoff.reset();
|
|
assert.strictEqual(backoff.duration(), 100);
|
|
assert.strictEqual(backoff.duration(), 200);
|
|
});
|
|
});
|