Example #1
0
 /**
  * at times api calls require the system to wait until an instance/image
  * is available. To do so repeated calls are made to ascertain the current
  * state of things. Given some apis have a rate limit it would be best
  * in such cases to halt/sleep the process for a predefined period time before
  * retrying. This test verifies that sleep period (in seconds) is customisable
  */
 public function testConfigurableSleepTime()
 {
     $sleepTime = 1;
     $callCount = 0;
     $client = new Client();
     $client->setCredentials(['sleep.interval' => $sleepTime]);
     $this->patchClassMethod('App\\Platform\\Aws\\Client::getEc2Client', function () use(&$callCount) {
         $mockEc2Client = $this->getMockEc2Client(['describeImages']);
         $mockEc2Client->expects($this->any())->method('describeImages')->will($this->returnCallback(function () use(&$callCount) {
             ++$callCount;
             if ($callCount < 3) {
                 return $this->getGuzzleModelResponse('aws/describe_images_response_sate_not_available');
             } else {
                 return $this->getGuzzleModelResponse('aws/describe_images_response');
             }
         }));
         return $mockEc2Client;
     }, 1);
     $start = time();
     $client->convertToImage('ami-123456');
     $this->assertEquals($sleepTime * ($callCount - 1), time() - $start);
 }