@@ -22,38 +22,21 @@ public function testAddTimerReturnsNonPeriodicTimerInstance()
22
22
$ this ->assertFalse ($ timer ->isPeriodic ());
23
23
}
24
24
25
- /**
26
- * @depends testPlatformHasHighAccuracy
27
- */
28
25
public function testAddTimerWillBeInvokedOnceAndBlocksLoopWhenRunning ()
29
26
{
30
- // Make no strict assumptions about actual time interval. Common
31
- // environments usually provide millisecond accuracy (or better), but
32
- // Travis and other CI systems are slow.
33
- // We try to compensate for this by skipping accurate tests when the
34
- // current platform is known to be inaccurate. We test this by sleeping
35
- // 3x1ms and then measure the time for each iteration before running the
36
- // actual test.
37
- for ($ i = 0 ; $ i < 3 ; ++$ i ) {
38
- $ start = microtime (true );
39
- usleep (1000 );
40
- $ time = microtime (true ) - $ start ;
41
-
42
- if ($ time < 0.001 || $ time > 0.002 ) {
43
- $ this ->markTestSkipped ('Platform provides insufficient accuracy ( ' . $ time . ' s) ' );
44
- }
45
- }
46
-
47
27
$ loop = $ this ->createLoop ();
48
28
49
- $ loop ->addTimer (0.001 , $ this ->expectCallableOnce ());
29
+ $ loop ->addTimer (0.002 , $ this ->expectCallableOnce ());
50
30
51
31
$ start = microtime (true );
52
32
$ loop ->run ();
53
33
$ end = microtime (true );
54
34
35
+ // 1 invocation should take 2ms (± 1ms due to timer inaccuracies)
36
+ // make no strict assumptions about time interval, must at least take 1ms
37
+ // and should not take longer than 0.1s for slower loops.
55
38
$ this ->assertGreaterThanOrEqual (0.001 , $ end - $ start );
56
- $ this ->assertLessThan (0.002 , $ end - $ start );
39
+ $ this ->assertLessThan (0.1 , $ end - $ start );
57
40
}
58
41
59
42
public function testAddPeriodicTimerReturnsPeriodicTimerInstance ()
@@ -122,10 +105,10 @@ public function testAddPeriodicTimerCancelsItself()
122
105
123
106
$ this ->assertEquals (5 , $ i );
124
107
125
- // make no strict assumptions about time interval.
126
- // 5 invocations must take at least 0.005s (5ms) and should not take
127
- // longer than 0.1s for slower loops.
128
- $ this ->assertGreaterThanOrEqual (0.005 , $ end - $ start );
108
+ // 5 invocations should take 5ms (± 1ms due to timer inaccuracies)
109
+ // make no strict assumptions about time interval, must at least take 4ms
110
+ // and should not take longer than 0.1s for slower loops.
111
+ $ this ->assertGreaterThanOrEqual (0.004 , $ end - $ start );
129
112
$ this ->assertLessThan (0.1 , $ end - $ start );
130
113
}
131
114
0 commit comments