<?php
require_once "vendor/autoload.php";
use GuzzleHttp\Promise;
use GuzzleHttp\Psr7\Request;
$pluginClient = new \Http\Client\Common\PluginClient(
new \Http\Client\Curl\Client(\Http\Discovery\MessageFactoryDiscovery::find(), \Http\Discovery\StreamFactoryDiscovery::find())
);
$iteration = 1;
$exit = 0;
while (TRUE) {
if ($iteration > 20) {
echo('Passed' . PHP_EOL);
break;
}
// Initiate each request but do not block
$promises = [
$pluginClient->sendAsyncRequest(new Request('GET', 'http://httpbin.org/status/500')),
$pluginClient->sendAsyncRequest(new Request('GET', 'http://httpbin.org/status/404')),
$pluginClient->sendAsyncRequest(new Request('GET', 'http://httpbin.org/status/404')),
$pluginClient->sendAsyncRequest(new Request('GET', 'http://httpbin.org/status/404')),
$pluginClient->sendAsyncRequest(new Request('GET', 'http://httpbin.org/status/404')),
$pluginClient->sendAsyncRequest(new Request('GET', 'http://httpbin.org/status/404')),
$pluginClient->sendAsyncRequest(new Request('GET', 'http://httpbin.org/status/404')),
$pluginClient->sendAsyncRequest(new Request('GET', 'http://httpbin.org/status/200')),
];
try {
// Wait for the requests to complete, even if some of them fail
$results = Promise\settle($promises)->wait();
foreach ($results as $result) {
if ($result['state'] === Promise\Promise::REJECTED && is_string($result['reason'])) {
printf("Iteration: %d. %s\n", $iteration, $result['reason']);
$exit = 1;
break 2;
}
}
$iteration++;
}
catch (\Exception $e) {
printf("Exception should not be thrown. %s\n", get_class($e));
$exit = 1;
break;
}
}
exit($exit);
[email protected]:/var/www/html $ ./testrunner.sh
Passed
Passed
Passed
Passed
Passed
Passed
Passed
Passed
Passed
Iteration: 1. Invoking the wait callback did not resolve the promise
Failed after: 10 restarts.
[email protected]:/var/www/html $ ./testrunner.sh
Iteration: 1. Invoking the wait callback did not resolve the promise
Failed after: 1 restarts.
As you can see the tester either fails in the first iteration or it does not fail at all.