8
8
use Illuminate \Contracts \Support \Htmlable ;
9
9
use Illuminate \Support \Env ;
10
10
use Illuminate \Support \Optional ;
11
+ use Illuminate \Support \Sleep ;
11
12
use Illuminate \Support \Stringable ;
12
13
use Illuminate \Tests \Support \Fixtures \IntBackedEnum ;
13
14
use Illuminate \Tests \Support \Fixtures \StringBackedEnum ;
@@ -775,7 +776,7 @@ public function something()
775
776
776
777
public function testRetry ()
777
778
{
778
- $ startTime = microtime ( true );
779
+ Sleep:: fake ( );
779
780
780
781
$ attempts = retry (2 , function ($ attempts ) {
781
782
if ($ attempts > 1 ) {
@@ -789,12 +790,16 @@ public function testRetry()
789
790
$ this ->assertEquals (2 , $ attempts );
790
791
791
792
// Make sure we waited 100ms for the first attempt
792
- $ this ->assertEqualsWithDelta (0.1 , microtime (true ) - $ startTime , 0.03 );
793
+ Sleep::assertSleptTimes (1 );
794
+
795
+ Sleep::assertSequence ([
796
+ Sleep::usleep (100_000 ),
797
+ ]);
793
798
}
794
799
795
800
public function testRetryWithPassingSleepCallback ()
796
801
{
797
- $ startTime = microtime ( true );
802
+ Sleep:: fake ( );
798
803
799
804
$ attempts = retry (3 , function ($ attempts ) {
800
805
if ($ attempts > 2 ) {
@@ -812,12 +817,17 @@ public function testRetryWithPassingSleepCallback()
812
817
$ this ->assertEquals (3 , $ attempts );
813
818
814
819
// Make sure we waited 300ms for the first two attempts
815
- $ this ->assertEqualsWithDelta (0.3 , microtime (true ) - $ startTime , 0.03 );
820
+ Sleep::assertSleptTimes (2 );
821
+
822
+ Sleep::assertSequence ([
823
+ Sleep::usleep (100_000 ),
824
+ Sleep::usleep (200_000 ),
825
+ ]);
816
826
}
817
827
818
828
public function testRetryWithPassingWhenCallback ()
819
829
{
820
- $ startTime = microtime ( true );
830
+ Sleep:: fake ( );
821
831
822
832
$ attempts = retry (2 , function ($ attempts ) {
823
833
if ($ attempts > 1 ) {
@@ -833,7 +843,11 @@ public function testRetryWithPassingWhenCallback()
833
843
$ this ->assertEquals (2 , $ attempts );
834
844
835
845
// Make sure we waited 100ms for the first attempt
836
- $ this ->assertEqualsWithDelta (0.1 , microtime (true ) - $ startTime , 0.03 );
846
+ Sleep::assertSleptTimes (1 );
847
+
848
+ Sleep::assertSequence ([
849
+ Sleep::usleep (100_000 ),
850
+ ]);
837
851
}
838
852
839
853
public function testRetryWithFailingWhenCallback ()
@@ -853,7 +867,8 @@ public function testRetryWithFailingWhenCallback()
853
867
854
868
public function testRetryWithBackoff ()
855
869
{
856
- $ startTime = microtime (true );
870
+ Sleep::fake ();
871
+
857
872
$ attempts = retry ([50 , 100 , 200 ], function ($ attempts ) {
858
873
if ($ attempts > 3 ) {
859
874
return $ attempts ;
@@ -865,7 +880,13 @@ public function testRetryWithBackoff()
865
880
// Make sure we made four attempts
866
881
$ this ->assertEquals (4 , $ attempts );
867
882
868
- $ this ->assertEqualsWithDelta (0.05 + 0.1 + 0.2 , microtime (true ) - $ startTime , 0.05 );
883
+ Sleep::assertSleptTimes (3 );
884
+
885
+ Sleep::assertSequence ([
886
+ Sleep::usleep (50_000 ),
887
+ Sleep::usleep (100_000 ),
888
+ Sleep::usleep (200_000 ),
889
+ ]);
869
890
}
870
891
871
892
public function testTransform ()
0 commit comments