deno.land / std@0.177.1 / async / retry_test.ts

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.import { retry } from "./retry.ts";import { assert, assertRejects } from "../testing/asserts.ts";
function generateErroringFunction(errorsBeforeSucceeds: number) { let errorCount = 0;
return () => { if (errorCount >= errorsBeforeSucceeds) { return errorCount; } errorCount++; throw `Only errored ${errorCount} times`; };}
Deno.test("[async] retry", async function () { const threeErrors = generateErroringFunction(3); const result = await retry(threeErrors, { minTimeout: 100, }); assert(result === 3);});
Deno.test("[async] retry fails after max errors is passed", async function () { const fiveErrors = generateErroringFunction(5); await assertRejects(() => retry(fiveErrors, { minTimeout: 100, }) );});
Deno.test("[async] retry throws if minTimeout is less than maxTimeout", async function () { await assertRejects(() => retry(() => {}, { minTimeout: 1000, maxTimeout: 100, }) );});
std

Version Info

Tagged at
11 months ago