Example #1
0
             $stubborn->staticBackoff(1);
         }
     })->retries(2)->run(function () {
         return 1;
     });
     // kind of arbitrary, can't think of a more accurate way to test
     // this at this point
     expect($stubborn->totalBackoffTime())->to->be(2);
     expect($stubborn->totalTries())->to->be(3);
     expect($result)->to->be(1);
 });
 it('->exponentialBackoff()', function ($test) {
     $stubborn = new Stubborn();
     $result = $stubborn->resultHandler(function ($stubborn) {
         if ($stubborn->retries() < $stubborn->maxRetries()) {
             $stubborn->exponentialBackoff();
         }
     })->retries(2)->run(function () {
         return 77;
     });
     // kind of arbitrary, can't think of a more accurate way to test
     // this at this point
     expect($stubborn->totalBackoffTime())->to->be->within(3, 5);
     expect($stubborn->totalTries())->to->be(3);
     expect($result)->to->be(77);
 });
 it('->delayRetry()', function ($test) {
     $stubborn = new Stubborn();
     $result = $stubborn->retries(1)->resultHandler(function ($stubborn) {
         $stubborn->delayRetry();
     })->run(function () {