@studio-foundation/ralph 0.3.0-beta.1 → 0.3.0-beta.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,87 +0,0 @@
1
- import { describe, it, expect } from 'vitest';
2
- import { noDelay, fixedDelay, exponentialBackoff } from '../src/retry-strategy.js';
3
-
4
- describe('noDelay', () => {
5
- it('always returns 0', () => {
6
- const strategy = noDelay();
7
- expect(strategy.getDelay(1)).toBe(0);
8
- expect(strategy.getDelay(2)).toBe(0);
9
- expect(strategy.getDelay(100)).toBe(0);
10
- });
11
-
12
- it('returns 0 for all attempts', () => {
13
- const strategy = noDelay();
14
- for (let i = 1; i <= 10; i++) {
15
- expect(strategy.getDelay(i)).toBe(0);
16
- }
17
- });
18
- });
19
-
20
- describe('fixedDelay', () => {
21
- it('always returns same delay', () => {
22
- const strategy = fixedDelay(1000);
23
- expect(strategy.getDelay(1)).toBe(1000);
24
- expect(strategy.getDelay(2)).toBe(1000);
25
- expect(strategy.getDelay(5)).toBe(1000);
26
- expect(strategy.getDelay(100)).toBe(1000);
27
- });
28
-
29
- it('works with different delay values', () => {
30
- expect(fixedDelay(500).getDelay(1)).toBe(500);
31
- expect(fixedDelay(2000).getDelay(1)).toBe(2000);
32
- expect(fixedDelay(100).getDelay(1)).toBe(100);
33
- });
34
-
35
- it('works with zero delay', () => {
36
- const strategy = fixedDelay(0);
37
- expect(strategy.getDelay(1)).toBe(0);
38
- });
39
- });
40
-
41
- describe('exponentialBackoff', () => {
42
- it('doubles each attempt', () => {
43
- const strategy = exponentialBackoff(1000, 10000);
44
- expect(strategy.getDelay(1)).toBe(1000); // 1000 * 2^0
45
- expect(strategy.getDelay(2)).toBe(2000); // 1000 * 2^1
46
- expect(strategy.getDelay(3)).toBe(4000); // 1000 * 2^2
47
- expect(strategy.getDelay(4)).toBe(8000); // 1000 * 2^3
48
- });
49
-
50
- it('caps at maxMs', () => {
51
- const strategy = exponentialBackoff(1000, 5000);
52
- expect(strategy.getDelay(1)).toBe(1000);
53
- expect(strategy.getDelay(2)).toBe(2000);
54
- expect(strategy.getDelay(3)).toBe(4000);
55
- expect(strategy.getDelay(4)).toBe(5000); // Would be 8000 but capped
56
- expect(strategy.getDelay(5)).toBe(5000); // Would be 16000 but capped
57
- expect(strategy.getDelay(10)).toBe(5000); // Would be 512000 but capped
58
- });
59
-
60
- it('works with different base values', () => {
61
- const strategy = exponentialBackoff(100, 10000);
62
- expect(strategy.getDelay(1)).toBe(100);
63
- expect(strategy.getDelay(2)).toBe(200);
64
- expect(strategy.getDelay(3)).toBe(400);
65
- expect(strategy.getDelay(4)).toBe(800);
66
- });
67
-
68
- it('respects max from the start if base > max', () => {
69
- const strategy = exponentialBackoff(10000, 5000);
70
- expect(strategy.getDelay(1)).toBe(5000); // 10000 capped to 5000
71
- });
72
-
73
- it('handles large attempt numbers without overflow', () => {
74
- const strategy = exponentialBackoff(1000, 60000);
75
- const delay = strategy.getDelay(100);
76
- expect(delay).toBe(60000); // Should be capped, not Infinity
77
- expect(delay).toBeLessThanOrEqual(60000);
78
- });
79
-
80
- it('works with small max values', () => {
81
- const strategy = exponentialBackoff(10, 50);
82
- expect(strategy.getDelay(1)).toBe(10);
83
- expect(strategy.getDelay(2)).toBe(20);
84
- expect(strategy.getDelay(3)).toBe(40);
85
- expect(strategy.getDelay(4)).toBe(50); // Capped
86
- });
87
- });