@@ -12,15 +12,15 @@ import XCTest
12
12
13
13
final class ExponentialBackoffTests : XCTestCase {
14
14
func testExponentialBackoff( ) {
15
- var backoff = ExponentialBackoff ( initial: . seconds( 2 ) , multiplier: 3 )
15
+ var backoff = ExponentialBackoff ( initial: . seconds( 2 ) , multiplier: 3 , maxDelay : . seconds ( 18 ) )
16
16
17
17
XCTAssertEqual ( backoff. next ( ) , . seconds( 2 ) )
18
18
XCTAssertEqual ( backoff. next ( ) , . seconds( 6 ) )
19
19
XCTAssertEqual ( backoff. next ( ) , . seconds( 18 ) )
20
20
}
21
21
22
22
func testAtMaximumValue( ) {
23
- var backoff = ExponentialBackoff ( initial: . milliseconds( . max - 1 ) , multiplier: 2 )
23
+ var backoff = ExponentialBackoff ( initial: . milliseconds( . max - 1 ) , multiplier: 2 , maxDelay : . seconds ( . max - 1 ) )
24
24
25
25
XCTAssertEqual ( backoff. next ( ) , . milliseconds( . max - 1 ) )
26
26
XCTAssertEqual ( backoff. next ( ) , . milliseconds( . max) )
@@ -40,20 +40,20 @@ final class ExponentialBackoffTests: XCTestCase {
40
40
}
41
41
42
42
func testMinimumValue( ) {
43
- var backoff = ExponentialBackoff ( initial: . milliseconds( 0 ) , multiplier: 10 )
43
+ var backoff = ExponentialBackoff ( initial: . milliseconds( 0 ) , multiplier: 10 , maxDelay : . milliseconds ( 0 ) )
44
44
45
45
XCTAssertEqual ( backoff. next ( ) , . milliseconds( 0 ) )
46
46
XCTAssertEqual ( backoff. next ( ) , . milliseconds( 0 ) )
47
47
48
- backoff = ExponentialBackoff ( initial: . milliseconds( 1 ) , multiplier: 0 )
48
+ backoff = ExponentialBackoff ( initial: . milliseconds( 1 ) , multiplier: 0 , maxDelay : . zero )
49
49
50
- XCTAssertEqual ( backoff. next ( ) , . milliseconds( 1 ) )
50
+ XCTAssertEqual ( backoff. next ( ) , . milliseconds( 0 ) )
51
51
XCTAssertEqual ( backoff. next ( ) , . milliseconds( 0 ) )
52
52
}
53
53
54
54
func testJitter( ) {
55
55
let initial : Duration = . milliseconds( 500 )
56
- var iterator = Jittered ( ExponentialBackoff ( initial: initial, multiplier: 3 ) )
56
+ var iterator = Jittered ( ExponentialBackoff ( initial: initial, multiplier: 3 , maxDelay : . milliseconds ( 1500 ) ) )
57
57
58
58
XCTAssertGreaterThanOrEqual ( iterator. next ( ) !, initial)
59
59
}
0 commit comments