@@ -67,7 +67,7 @@ public function testGetDelay(int $delay, int $multiplier, int $maxDelay, int $pr
6767
6868 public static function provideDelay (): iterable
6969 {
70- // delay, multiplier, maxDelay, retries , expectedDelay
70+ // delay, multiplier, maxDelay, previousRetries , expectedDelay
7171 yield [1000 , 1 , 5000 , 0 , 1000 ];
7272 yield [1000 , 1 , 5000 , 1 , 1000 ];
7373 yield [1000 , 1 , 5000 , 2 , 1000 ];
@@ -90,13 +90,16 @@ public static function provideDelay(): iterable
9090 yield [0 , 2 , 10000 , 1 , 0 ];
9191 }
9292
93- public function testJitter ()
93+ /**
94+ * @dataProvider provideJitter
95+ */
96+ public function testJitter (float $ multiplier , int $ previousRetries )
9497 {
95- $ strategy = new GenericRetryStrategy ([], 1000 , 1 , 0 , 1 );
98+ $ strategy = new GenericRetryStrategy ([], 1000 , $ multiplier , 0 , 1 );
9699 $ min = 2000 ;
97100 $ max = 0 ;
98101 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 );
100103 $ min = min ($ min , $ delay );
101104 $ max = max ($ max , $ delay );
102105 }
@@ -105,6 +108,13 @@ public function testJitter()
105108 $ this ->assertLessThanOrEqual (1000 , $ min );
106109 }
107110
111+ public static function provideJitter (): iterable
112+ {
113+ // multiplier, previousRetries
114+ yield [1 , 0 ];
115+ yield [1.1 , 2 ];
116+ }
117+
108118 private function getContext ($ retryCount , $ method , $ url , $ statusCode ): AsyncContext
109119 {
110120 $ passthru = null ;
0 commit comments