@@ -67,7 +67,7 @@ public function testGetDelay(int $delay, int $multiplier, int $maxDelay, int $pr
67
67
68
68
public static function provideDelay (): iterable
69
69
{
70
- // delay, multiplier, maxDelay, retries , expectedDelay
70
+ // delay, multiplier, maxDelay, previousRetries , expectedDelay
71
71
yield [1000 , 1 , 5000 , 0 , 1000 ];
72
72
yield [1000 , 1 , 5000 , 1 , 1000 ];
73
73
yield [1000 , 1 , 5000 , 2 , 1000 ];
@@ -90,13 +90,16 @@ public static function provideDelay(): iterable
90
90
yield [0 , 2 , 10000 , 1 , 0 ];
91
91
}
92
92
93
- public function testJitter ()
93
+ /**
94
+ * @dataProvider provideJitter
95
+ */
96
+ public function testJitter (float $ multiplier , int $ previousRetries )
94
97
{
95
- $ strategy = new GenericRetryStrategy ([], 1000 , 1 , 0 , 1 );
98
+ $ strategy = new GenericRetryStrategy ([], 1000 , $ multiplier , 0 , 1 );
96
99
$ min = 2000 ;
97
100
$ max = 0 ;
98
101
for ($ i = 0 ; $ i < 50 ; ++$ i ) {
99
- $ delay = $ strategy ->getDelay ($ this ->getContext (0 , 'GET ' , 'http://example.com/ ' , 200 ), null , null );
102
+ $ delay = $ strategy ->getDelay ($ this ->getContext ($ previousRetries , 'GET ' , 'http://example.com/ ' , 200 ), null , null );
100
103
$ min = min ($ min , $ delay );
101
104
$ max = max ($ max , $ delay );
102
105
}
@@ -105,6 +108,13 @@ public function testJitter()
105
108
$ this ->assertLessThanOrEqual (1000 , $ min );
106
109
}
107
110
111
+ public static function provideJitter (): iterable
112
+ {
113
+ // multiplier, previousRetries
114
+ yield [1 , 0 ];
115
+ yield [1.1 , 2 ];
116
+ }
117
+
108
118
private function getContext ($ retryCount , $ method , $ url , $ statusCode ): AsyncContext
109
119
{
110
120
$ passthru = null ;
0 commit comments