/**
  * @param LocationInterface $location
  * @param Request           $request
  *
  * @return Response\Promise
  *
  * @throws \Exception
  */
 public function call(LocationInterface $location, Request $request)
 {
     $interaction = Interaction::call($location, $request);
     $this->profile->add($interaction);
     $interaction->start();
     try {
         $promise = $this->driver->call($location, $request);
     } catch (\Exception $exception) {
         $interaction->fail($exception);
         $interaction->stop();
         throw $exception;
     }
     $interaction->stop();
     return new Response\Promise(function ($timeout) use($promise, $interaction) {
         $interaction->start();
         try {
             $response = $promise->resolve($timeout);
         } catch (\Exception $exception) {
             $interaction->stop();
             $interaction->fail($exception);
             throw $exception;
         }
         $interaction->reply($response);
         $interaction->stop();
         return $response;
     });
 }
 public function testCountExceptionsByType()
 {
     $e = new \Exception();
     $this->profile->add(Profile\Interaction::publish(new Location('foo'), new Request('foo', '0')))->add(Profile\Interaction::publish(new Location('foo'), new Request('foo', '0'))->fail($e))->add(Profile\Interaction::call(new Location('foo'), new Request('foo', '0')))->add(Profile\Interaction::call(new Location('foo'), new Request('foo', '0'))->fail($e))->add(Profile\Interaction::broadcast(new Request('foo', '0')))->add(Profile\Interaction::broadcast(new Request('foo', '0'))->fail($e))->add(Profile\Interaction::publish(new Location('foo'), new Request('foo', '0')))->add(Profile\Interaction::publish(new Location('foo'), new Request('foo', '0'))->fail($e))->add(Profile\Interaction::call(new Location('foo'), new Request('foo', '0')))->add(Profile\Interaction::call(new Location('foo'), new Request('foo', '0'))->fail($e))->add(Profile\Interaction::publish(new Location('foo'), new Request('foo', '0')))->add(Profile\Interaction::publish(new Location('foo'), new Request('foo', '0'))->fail($e));
     $this->assertEquals(6, $this->profile->countExceptions());
     $this->assertEquals(3, $this->profile->countPublishExceptions());
     $this->assertEquals(2, $this->profile->countCallExceptions());
     $this->assertEquals(1, $this->profile->countBroadcastExceptions());
 }
 /**
  * Interaction should take into account all start-stop calls.
  */
 public function testDuration()
 {
     $interaction = Interaction::broadcast(new Request('foo', '0'));
     $interaction->start();
     usleep(10);
     $interaction->stop();
     $durationA = $interaction->getDuration();
     $interaction->start();
     usleep(5);
     $interaction->stop();
     $durationB = $interaction->getDuration();
     $this->assertTrue($durationB > $durationA, 'Duration B should include Duration A and time of second delay');
 }
 public function indexAction()
 {
     $this->profile->add(Profile\Interaction::broadcast(new Message\Request('qux', '1.0', []))->start()->stop(usleep(15000)))->add(Profile\Interaction::publish(new Location('foo'), new Message\Request('baz', '1.0', []))->start()->stop(usleep(10000)))->add(Profile\Interaction::call(new Location('bar'), new Message\Request('boom', '1.0', []))->start()->reply(new Message\Response('reply'))->stop(usleep(25000)))->add(Profile\Interaction::call(new Location('bar'), new Message\Request('bug', '1.0', []))->start()->fail(new \Exception('oops...'))->stop(usleep(25000)));
     return new Response('<html><body><h1>Test Web Profiler</h1><p>Check out this awesome toolbar below!</p></body></html>');
 }