Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 18 additions & 34 deletions tests/Integration/Queue/ProcessorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -313,45 +313,29 @@ public function test_process_ShouldActuallyRetryProcessingAllRequestsWithoutTheF
->setConstructorArgs(array($this->queue, $this->lock))
->getMock();

$mock->expects($this->at(0))
->method('processRequestSets')
->with($this->anything(), $this->callback(function ($arg) {
return 2 === count($arg) && 1 === $arg[0]->getNumberOfRequests() && 5 === $arg[1]->getNumberOfRequests();
}))
->will($this->returnCallback($forwardCallToProcessor));

$mock->expects($this->at(1))
->method('processRequestSets')
->with($this->anything(), $this->equalTo(array()))
->will($this->returnCallback($forwardCallToProcessor));

$mock->expects($this->at(2)) // one of them fails
->method('processRequestSets')
->with($this->anything(), $this->callback(function ($arg) {
return 2 === count($arg) && 1 === $arg[0]->getNumberOfRequests() && 2 === $arg[1]->getNumberOfRequests();
}))
->will($this->returnCallback($forwardCallToProcessor));

$mock->expects($this->at(3)) // retry, this time it should work
$expectedRequestSetCalls = [
[1, 5],
[],
[1, 2],
[1],
[3, 1],
[],
];
$mock->expects($this->exactly(count($expectedRequestSetCalls)))
->method('processRequestSets')
->with($this->anything(), $this->callback(function ($arg) {
return 1 === count($arg) && 1 === $arg[0]->getNumberOfRequests();
}))
->will($this->returnCallback($forwardCallToProcessor));
->willReturnCallback(function ($tracker, $queuedRequestSets) use (&$expectedRequestSetCalls, $forwardCallToProcessor) {
$expectedCounts = array_shift($expectedRequestSetCalls);
$actualCounts = array_map(function ($requestSet) {
return $requestSet->getNumberOfRequests();
}, $queuedRequestSets);

$mock->expects($this->at(4)) // both of them fails
->method('processRequestSets')
->with($this->anything(), $this->callback(function ($arg) {
return 2 === count($arg) && 3 === $arg[0]->getNumberOfRequests() && 1 === $arg[1]->getNumberOfRequests();
}))
->will($this->returnCallback($forwardCallToProcessor));
$this->assertSame($expectedCounts, $actualCounts);

$mock->expects($this->at(5)) // as both fail none should be retried
->method('processRequestSets')
->with($this->anything(), $this->equalTo(array()))
->will($this->returnCallback($forwardCallToProcessor));
return $forwardCallToProcessor($tracker, $queuedRequestSets);
});

$mock->process($this->createTracker());
$this->assertSame([], $expectedRequestSetCalls);
}

public function test_process_shouldRestoreEnvironmentAfterTrackingRequests()
Expand Down
Loading