Example #1
0
 public function testCallbackRunsAfterTimeout()
 {
     $threshold = 0.01;
     $loop = new Client(new LoopHandler());
     $t1Actual = $t2Actual = null;
     $t1Expected = microtime(true);
     $t2Expected = microtime(true) + 3;
     $promise1 = $loop->enqueue(function () use(&$t1Actual) {
         $t1Actual = microtime(true);
     });
     $promise2 = $loop->enqueueIn(3, function () use(&$t2Actual) {
         $t2Actual = microtime(true);
     });
     \GuzzleHttp\Promise\all([$promise1, $promise2])->wait();
     $this->assertGreaterThan($t1Expected - $threshold, $t1Actual);
     $this->assertLessThan($t1Expected + $threshold, $t1Actual);
     $this->assertGreaterThan($t2Expected - $threshold, $t2Actual);
     $this->assertLessThan($t2Expected + $threshold, $t2Actual);
 }