File tree Expand file tree Collapse file tree 3 files changed +24
-38
lines changed Expand file tree Collapse file tree 3 files changed +24
-38
lines changed Original file line number Diff line number Diff line change @@ -195,11 +195,11 @@ public function run()
195
195
if ($ timeout < 0 ) {
196
196
$ timeout = 0 ;
197
197
} else {
198
- /*
199
- * round() needed to correct float error:
200
- * https://github.com/reactphp/event- loop/issues/48
201
- */
202
- $ timeout = round ( $ timeout * self :: MICROSECONDS_PER_SECOND ) ;
198
+ // Convert float seconds to int microseconds.
199
+ // Ensure we do not exceed maximum integer size, which may
200
+ // cause the loop to tick once every ~35min on 32bit systems.
201
+ $ timeout *= self :: MICROSECONDS_PER_SECOND ;
202
+ $ timeout = $ timeout > PHP_INT_MAX ? PHP_INT_MAX : ( int ) $ timeout ;
203
203
}
204
204
205
205
// The only possible event is stream activity, so wait forever ...
@@ -222,6 +222,8 @@ public function stop()
222
222
223
223
/**
224
224
* Wait/check for stream activity, or until the next timer is due.
225
+ *
226
+ * @param integer|null $timeout Activity timeout in microseconds, or null to wait forever.
225
227
*/
226
228
private function waitForStreamActivity ($ timeout )
227
229
{
Original file line number Diff line number Diff line change @@ -480,6 +480,23 @@ public function testSignalsKeepTheLoopRunningAndRemovingItStopsTheLoop()
480
480
$ this ->assertRunFasterThan (1.6 );
481
481
}
482
482
483
+ public function testTimerIntervalCanBeFarInFuture ()
484
+ {
485
+ // get only one part of the pair to ensure the other side will close immediately
486
+ list ($ stream ) = $ this ->createSocketPair ();
487
+
488
+ // start a timer very far in the future
489
+ $ timer = $ this ->loop ->addTimer (PHP_INT_MAX , function () { });
490
+
491
+ // remove stream and timer when the stream is readable (closes)
492
+ $ this ->loop ->addReadStream ($ stream , function ($ stream ) use ($ timer ) {
493
+ $ this ->loop ->removeReadStream ($ stream );
494
+ $ this ->loop ->cancelTimer ($ timer );
495
+ });
496
+
497
+ $ this ->assertRunFasterThan ($ this ->tickTimeout );
498
+ }
499
+
483
500
private function assertRunSlowerThan ($ minInterval )
484
501
{
485
502
$ start = microtime (true );
Original file line number Diff line number Diff line change 4
4
5
5
use React \EventLoop \LoopInterface ;
6
6
use React \EventLoop \StreamSelectLoop ;
7
- use React \EventLoop \Timer \Timer ;
8
7
9
8
class StreamSelectLoopTest extends AbstractLoopTest
10
9
{
@@ -144,36 +143,4 @@ protected function forkSendSignal($signal)
144
143
die ();
145
144
}
146
145
}
147
-
148
- /**
149
- * https://github.com/reactphp/event-loop/issues/48
150
- *
151
- * Tests that timer with very small interval uses at least 1 microsecond
152
- * timeout.
153
- */
154
- public function testSmallTimerInterval ()
155
- {
156
- /** @var StreamSelectLoop|\PHPUnit_Framework_MockObject_MockObject $loop */
157
- $ loop = $ this ->getMockBuilder ('React\EventLoop\StreamSelectLoop ' )
158
- ->setMethods (['streamSelect ' ])
159
- ->getMock ();
160
- $ loop
161
- ->expects ($ this ->at (0 ))
162
- ->method ('streamSelect ' )
163
- ->with ([], [], 1 );
164
- $ loop
165
- ->expects ($ this ->at (1 ))
166
- ->method ('streamSelect ' )
167
- ->with ([], [], 0 );
168
-
169
- $ callsCount = 0 ;
170
- $ loop ->addPeriodicTimer (Timer::MIN_INTERVAL , function () use (&$ loop , &$ callsCount ) {
171
- $ callsCount ++;
172
- if ($ callsCount == 2 ) {
173
- $ loop ->stop ();
174
- }
175
- });
176
-
177
- $ loop ->run ();
178
- }
179
146
}
You can’t perform that action at this time.
0 commit comments