runner.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. use Ratchet\Client\WebSocket;
  3. use React\Promise\Deferred;
  4. require __DIR__ . '/../../vendor/autoload.php';
  5. define('AGENT', 'Pawl/0.4');
  6. $connFactory = function() {
  7. $connector = new Ratchet\Client\Connector();
  8. return function($url) use ($connector) {
  9. return $connector('ws://127.0.0.1:9001' . $url);
  10. };
  11. };
  12. $connector = $connFactory();
  13. $connector('/getCaseCount')
  14. ->then(function(WebSocket $conn) {
  15. $futureNum = new Deferred;
  16. $conn->on('message', function($msg) use ($futureNum) {
  17. $futureNum->resolve($msg);
  18. });
  19. return $futureNum->promise();
  20. }, function($e) {
  21. echo "Could not connect to test server: {$e->getMessage()}\n";
  22. })->then(function($numOfCases) use ($connector) {
  23. echo "Running {$numOfCases} test cases\n\n";
  24. $allCases = new Deferred;
  25. $i = 0;
  26. $runNextCase = function() use (&$runNextCase, &$i, $numOfCases, $allCases, $connector) {
  27. $i++;
  28. if ($i > (int)$numOfCases->getPayload()) {
  29. $allCases->resolve();
  30. return;
  31. }
  32. echo ".";
  33. $connector("/runCase?case={$i}&agent=" . AGENT)->then(function(WebSocket $conn) use ($runNextCase) {
  34. $conn->on('message', function($msg, $conn) {
  35. $conn->send($msg);
  36. });
  37. $conn->on('close', $runNextCase);
  38. });
  39. };
  40. $runNextCase();
  41. return $allCases->promise();
  42. })->then(function() use ($connector) {
  43. $connector('/updateReports?agent=' . AGENT)->then(function(WebSocket $conn) {
  44. echo "\nDone!\n";
  45. $conn->on('close', function () {
  46. \React\EventLoop\Loop::stop();
  47. });
  48. });
  49. });