File tree Expand file tree Collapse file tree 3 files changed +52
-0
lines changed
tests/Unit/Extension/Core/Stage/Valve Expand file tree Collapse file tree 3 files changed +52
-0
lines changed Original file line number Diff line number Diff line change 14
14
use PhpBench \Pipeline \Extension \Core \Stage \Aggregator \DescribeAggregator ;
15
15
use PhpBench \Pipeline \Extension \Core \Stage \Parameter \CounterParameter ;
16
16
use PhpBench \Pipeline \Extension \Core \Stage \Valve \DelayValve ;
17
+ use PhpBench \Pipeline \Extension \Core \Stage \Valve \TimeoutValve ;
17
18
18
19
class CoreExtension implements PipelineExtension
19
20
{
@@ -35,6 +36,7 @@ public function __construct()
35
36
'sampler/curl ' => new CurlSampler (),
36
37
'valve/delay ' => new DelayValve (),
37
38
'valve/take ' => new TakeValve (),
39
+ 'valve/timeout ' => new TimeoutValve (),
38
40
];
39
41
}
40
42
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace PhpBench \Pipeline \Extension \Core \Stage \Valve ;
4
+
5
+ use PhpBench \Pipeline \Core \Stage ;
6
+ use Generator ;
7
+ use PhpBench \Pipeline \Core \Schema ;
8
+
9
+ class TimeoutValve implements Stage
10
+ {
11
+ public function __invoke (): Generator
12
+ {
13
+ list ($ config , $ data ) = yield ;
14
+
15
+ $ runningTime = 0 ;
16
+ $ start = microtime (true );
17
+ while ($ runningTime < $ config ['time ' ]) {
18
+ list ($ config , $ data ) = yield $ data ;
19
+ $ runningTime = (microtime (true ) - $ start ) * 1E6 ;
20
+ }
21
+ }
22
+
23
+ public function configure (Schema $ schema )
24
+ {
25
+ $ schema ->setDefaults ([
26
+ 'time ' => 1E6 ,
27
+ ]);
28
+ }
29
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace PhpBench \Pipeline \Tests \Unit \Extension \Core \Stage \Valve ;
4
+
5
+ use PHPUnit \Framework \TestCase ;
6
+ use PhpBench \Pipeline \Tests \Unit \Extension \Core \CoreTestCase ;
7
+
8
+ class TimeoutValveTest extends CoreTestCase
9
+ {
10
+ public function testTerminatesAfterAGivenNumberOfMicroseconds ()
11
+ {
12
+ $ start = microtime (true );
13
+ $ this ->pipeline ()
14
+ ->stage ('valve/timeout ' , [ 'time ' => 100000 ])
15
+ ->run ();
16
+
17
+ $ time = (microtime (true ) - $ start ) * 1E6 ;
18
+
19
+ $ this ->assertGreaterThanOrEqual (100000 , $ time );
20
+ }
21
+ }
You can’t perform that action at this time.
0 commit comments