public function test_integration_ShouldHonorWaitingTimes()
 {
     /*
      * Scenario:
      * 7 requests, 3 proxies
      * 1 - proxy_0 => successful request
      * 2 - proxy_1 => successful request
      * 3 - proxy_2 => successful request
      * 4 - proxy_0 => has to wait 5 seconds
      *   - proxy_2 => successful request
      * 5 - proxy_1 => has to wait 24 seconds
      *   - proxy_2 => has to wait 1 seconds
      *   - proxy_0 => failed request
      * 6 - proxy_2 => successful request
      * 7 - proxy_2 => has to wait 5 seconds
      *   - proxy_1 => has to wait 4 seconds
      *   - proxy_0 => has to wait 3 seconds
      * // sleep for 3 seconds - test by event
      *   - proxy_1 => has to wait 1 seconds
      *   - proxy_2 => has to wait 2 seconds
      *   - proxy_0 => successful request
      */
     $client = new Client();
     $numbers = [10, 0, 10];
     $times = [5, 10, 10, 20, 23, 30, 30, 30, 35];
     $h = $this->getHelper($numbers, $times);
     $interval = new RandomTimeInterval(0, 15, $h->getRandomMock(), $h->getTimeMock());
     $proxy0 = new RotatingProxy("0", null, 5, 10, $interval);
     $numbers = [29];
     $times = [5, 10, 10, 30, 30, 33, 33];
     $h = $this->getHelper($numbers, $times);
     $interval = new RandomTimeInterval(0, 15, $h->getRandomMock(), $h->getTimeMock());
     $proxy1 = new RotatingProxy("1", null, 5, 10, $interval);
     $numbers = [5, 8, 10];
     $times = [5, 10, 13, 20, 20, 25, 25, 30, 30, 33, 33];
     $h = $this->getHelper($numbers, $times);
     $interval = new RandomTimeInterval(0, 15, $h->getRandomMock(), $h->getTimeMock());
     $proxy2 = new RotatingProxy("2", null, 5, 10, $interval);
     $proxies = [$proxy0->getProxyString() => $proxy0, $proxy1->getProxyString() => $proxy1, $proxy2->getProxyString() => $proxy2];
     $success = true;
     $fail = false;
     $responses2Proxy = [[$success, $proxy0], [$success, $proxy1], [$success, $proxy2], [null, $proxy0], [$success, $proxy2], [null, $proxy1], [null, $proxy2], [$fail, $proxy0], [$success, $proxy2], [null, $proxy2], [null, $proxy1], [null, $proxy0], [null, $proxy1], [null, $proxy2], [$success, $proxy0]];
     $randKeys = [];
     $responses = [];
     foreach ($responses2Proxy as $key => $val) {
         $randKeys[] = array_search($val[1], $proxies);
         if ($val[0] !== null) {
             $responses[] = $val[0] ? new Response(200) : new Response(403);
         }
     }
     $h = $this->getHelper(null, null, $randKeys);
     $useOwnIp = false;
     $rotator = new ProxyRotator($proxies, $useOwnIp, $h->getRandomMock());
     $sub = new RotatingProxySubscriber($rotator);
     $mock = new Mock($responses);
     // Add the mock subscriber to the client.
     $client->getEmitter()->attach($mock);
     $client->getEmitter()->attach($sub);
     // build requests - we need to do this _after_ the $mock hast been attached to the client,
     // otherwise a real request is sent.
     $requests = [];
     foreach ($responses as $key => $val) {
         $req = $client->createRequest("GET");
         $req->getConfig()->set("request_id", $key);
         $requests[$key] = $req;
     }
     $checkState = function ($curProxy) use(&$responses2Proxy) {
         while (count($responses2Proxy) > 0) {
             $el = array_shift($responses2Proxy);
             if ($el === null) {
                 break;
             }
             if ($el[0] !== null) {
                 $this->assertEquals($curProxy, $el[1]->getProxyString());
                 break;
             }
         }
     };
     $sucFn = function (RequestInterface $request) use($checkState) {
         $proxy = $request->getConfig()->get("proxy");
         $checkState($proxy);
         //            echo "Success at request ".($request->getConfig()->get("request_id")+1)." using proxy ".$proxy."\n";
     };
     $errFn = function (RequestInterface $request, Exception $e) use($checkState) {
         $proxy = $request->getConfig()->get("proxy");
         $checkState($proxy);
         //            echo "Error at request ".($request->getConfig()->get("request_id")+1)." using proxy ".$proxy.": ".$e->getMessage()."\n";
     };
     $options = ["complete" => function (CompleteEvent $ev) use($sucFn) {
         $sucFn($ev->getRequest());
     }, "error" => function (ErrorEvent $ev) use($errFn) {
         $errFn($ev->getRequest(), $ev->getException());
     }];
     $pool = new Pool($client, $requests, $options);
     $pool->wait();
 }