-
Notifications
You must be signed in to change notification settings - Fork 3
/
retry-with-delay.spec.ts
103 lines (75 loc) 路 2.33 KB
/
retry-with-delay.spec.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import { iif } from 'rxjs';
import { configure } from 'rxjs-marbles';
import { retryWithDelay } from './retry-with-delay';
const { marbles } = configure({ run: false });
const error = 'error';
describe('retryWithDelay', () => {
it(
'should not change observable without errors',
marbles((m) => {
const input = m.cold('a-b-|', { a: 'a', b: 'b' });
const expected = input;
const result = input.pipe(retryWithDelay(1000, 20));
m.expect(result).toBeObservable(expected);
})
);
it(
'should never retry with a count of 0',
marbles((m) => {
m.bind();
const count = 0;
const delay = m.time('--|');
const source = m.cold('#', {}, error);
const expected = m.cold('#', {}, error);
const result = source.pipe(retryWithDelay(delay, count));
m.expect(result).toBeObservable(expected);
})
);
it(
'should retry [count] times with delay of [delay]',
marbles((m) => {
m.bind();
const count = 3;
const delay = m.time('--|');
const source = m.cold('#', {}, error);
// expect to be delayed by: 2 (delay) * 3 (count)
const expected = m.cold('------#', {}, error);
const result = source.pipe(retryWithDelay(delay, count));
m.expect(result).toBeObservable(expected);
})
);
it(
'amount of retries should default to 1',
marbles((m) => {
m.bind();
const delay = m.time('--|');
const source = m.cold('#', {}, error);
// expect to be delayed by: 2 (delay) * 1 (count)
const expected = m.cold('--#', {}, error);
const result = source.pipe(retryWithDelay(delay));
m.expect(result).toBeObservable(expected);
})
);
it(
'resubscribe each time',
marbles((m) => {
let firstCall = true;
m.bind();
const count = 1;
const delay = m.time('-|');
const source = iif(
() => {
const condition = firstCall;
firstCall = false;
return condition;
},
m.cold('--#', {}, error),
m.cold('--a', { a: 'a' })
);
// expect a to be delayed by: 2 (before first error) + 1 (delay) + 2 (before first value)
const expected = m.cold('-----a', { a: 'a' });
const result = source.pipe(retryWithDelay(delay, count));
m.expect(result).toBeObservable(expected);
})
);
});