@@ -121,28 +121,24 @@ public function testMinimumIntervalOneMicrosecond()
121121 $ this ->assertEquals (0.000001 , $ timer ->getInterval ());
122122 }
123123
124- public function testAddPeriodicTimerWithZeroIntervalWillBeInvokedWithMaximumAccuracyUntilItIsCancelled ()
124+ public function testAddPeriodicTimerWithZeroIntervalWillExecuteCallbackFunctionAtLeastTwice ()
125125 {
126126 $ loop = $ this ->createLoop ();
127127
128+ $ timeout = $ loop ->addTimer (2 , $ this ->expectCallableNever ()); //Timeout the test after two seconds if the periodic timer hasn't fired twice
129+
128130 $ i = 0 ;
129- $ periodic = $ loop ->addPeriodicTimer (0 , function () use (&$ i ) {
131+ $ loop ->addPeriodicTimer (0 , function ($ timer ) use (&$ i, $ loop , $ timeout ) {
130132 ++$ i ;
131- });
132-
133- $ this ->assertEquals ($ periodic ::MIN_INTERVAL , $ periodic ->getInterval ());
134-
135- $ loop ->addTimer (0.001 , function () use ($ loop , $ periodic ) {
136- $ loop ->cancelTimer ($ periodic );
133+ if ($ i === 2 ) {
134+ $ loop ->cancelTimer ($ timer );
135+ $ loop ->cancelTimer ($ timeout );
136+ }
137137 });
138138
139139 $ loop ->run ();
140140
141- // make no strict assumptions about number of invocations.
142- // we know it must be no more than 1000 times (1000 microseconds in 0.001 seconds) and should at least be
143- // invoked at least 2 times to prove it is repeating
144- $ this ->assertLessThanOrEqual (1000 , $ i );
145- $ this ->assertGreaterThanOrEqual (2 , $ i );
141+ $ this ->assertEquals (2 , $ i );
146142 }
147143
148144 public function testTimerIntervalBelowZeroRunsImmediately ()
0 commit comments