File tree Expand file tree Collapse file tree 2 files changed +36
-1
lines changed
Expand file tree Collapse file tree 2 files changed +36
-1
lines changed Original file line number Diff line number Diff line change @@ -186,7 +186,11 @@ public function run()
186186 if ($ timeout < 0 ) {
187187 $ timeout = 0 ;
188188 } else {
189- $ timeout *= self ::MICROSECONDS_PER_SECOND ;
189+ /*
190+ * round() needed to correct float error:
191+ * https://github.com/reactphp/event-loop/issues/48
192+ */
193+ $ timeout = round ($ timeout * self ::MICROSECONDS_PER_SECOND );
190194 }
191195
192196 // The only possible event is stream activity, so wait forever ...
Original file line number Diff line number Diff line change 44
55use React \EventLoop \LoopInterface ;
66use React \EventLoop \StreamSelectLoop ;
7+ use React \EventLoop \Timer \Timer ;
78
89class StreamSelectLoopTest extends AbstractLoopTest
910{
@@ -145,4 +146,34 @@ protected function forkSendSignal($signal)
145146 die ();
146147 }
147148 }
149+
150+ /**
151+ * https://github.com/reactphp/event-loop/issues/48
152+ *
153+ * Tests that timer with very small interval uses at least 1 microsecond
154+ * timeout.
155+ */
156+ public function testSmallTimerInterval ()
157+ {
158+ /** @var StreamSelectLoop|\PHPUnit_Framework_MockObject_MockObject $loop */
159+ $ loop = $ this ->getMock ('React\EventLoop\StreamSelectLoop ' , ['streamSelect ' ]);
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+ }
148179}
You can’t perform that action at this time.
0 commit comments