Skip to content

Commit dabe126

Browse files
committed
Fix retry sequence issue
Instead of using the number of retries as a limit, it was used as an offset, cutting off the first n elements of the sequence instead of limiting the sequence to n (where "n" is the number of retries).
1 parent 0794082 commit dabe126

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/Functional/Retry.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ function retry(callable $callback, $retries, Traversable $delaySequence = null)
3636
$delays = new AppendIterator();
3737
$delays->append(new InfiniteIterator($delaySequence));
3838
$delays->append(new InfiniteIterator(new ArrayIterator([0])));
39-
$delays = new LimitIterator($delays, $retries);
39+
$delays = new LimitIterator($delays, 0, $retries);
4040
} else {
4141
$delays = \array_fill_keys(\range(0, $retries), 0);
4242
}

tests/Functional/RetryTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,17 +139,17 @@ public function testDelayerSmallerThanRetries()
139139
$this->retryer
140140
->expects($this->at(2))
141141
->method('retry')
142-
->with(2, 10)
142+
->with(2, 30)
143143
->willThrowException(new Exception('third'));
144144
$this->retryer
145145
->expects($this->at(3))
146146
->method('retry')
147-
->with(3, 20)
147+
->with(3, 10)
148148
->willThrowException(new Exception('four'));
149149

150150
$this->expectException('Exception');
151151

152152
$this->expectExceptionMessage('four');
153-
retry([$this->retryer, 'retry'], 4, new ArrayIterator([1 => 10, 2 => 20]));
153+
retry([$this->retryer, 'retry'], 4, new ArrayIterator([10, 20, 30]));
154154
}
155155
}

0 commit comments

Comments
 (0)