@@ -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 ()
@@ -90,17 +73,17 @@ public function testAddPeriodicTimerWillBeInvokedWithMaximumAccuracyUntilItIsCan
90
73
++$ i ;
91
74
});
92
75
93
- $ loop ->addTimer (0.02 , function () use ($ loop , $ periodic ) {
76
+ $ loop ->addTimer (0.1 , function () use ($ loop , $ periodic ) {
94
77
$ loop ->cancelTimer ($ periodic );
95
78
});
96
79
97
80
$ loop ->run ();
98
81
99
82
// make no strict assumptions about number of invocations.
100
- // we know it must be no more than 20 times and should at least be
101
- // invoked twice for really slow loops
102
- $ this ->assertLessThanOrEqual (20 , $ i );
103
- $ this ->assertGreaterThan ( 2 , $ i );
83
+ // we know it must be no more than 100 times and should at least be
84
+ // invoked 4 times for really slow loops
85
+ $ this ->assertLessThanOrEqual (100 , $ i );
86
+ $ this ->assertGreaterThanOrEqual ( 4 , $ i );
104
87
}
105
88
106
89
public function testAddPeriodicTimerCancelsItself ()
@@ -122,11 +105,11 @@ 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 );
129
- $ this ->assertLessThan (0.1 , $ 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.2s for slower loops.
111
+ $ this ->assertGreaterThanOrEqual (0.004 , $ end - $ start );
112
+ $ this ->assertLessThan (0.2 , $ end - $ start );
130
113
}
131
114
132
115
public function testMinimumIntervalOneMicrosecond ()
0 commit comments