@@ -47,8 +47,6 @@ public function signalProvider()
47
47
];
48
48
}
49
49
50
- private $ _signalHandled = false ;
51
-
52
50
/**
53
51
* Test signal interrupt when no stream is attached to the loop
54
52
* @dataProvider signalProvider
@@ -59,20 +57,24 @@ public function testSignalInterruptNoStream($signal)
59
57
$ this ->markTestSkipped ('"pcntl" extension is required to run this test. ' );
60
58
}
61
59
62
- // dispatch signal handler once before signal is sent and once after
63
- $ this ->loop ->addTimer (0.01 , function () { pcntl_signal_dispatch (); });
64
- $ this -> loop -> addTimer ( 0.03 , function () { pcntl_signal_dispatch (); } );
65
- if ( defined ( ' HHVM_VERSION ' )) {
66
- // hhvm startup is slow so we need to add another handler much later
67
- $ this ->loop ->addTimer ( 0.5 , function () { pcntl_signal_dispatch (); } );
68
- }
60
+ // dispatch signal handler every 10ms for 0.1s
61
+ $ check = $ this ->loop ->addPeriodicTimer (0.01 , function () {
62
+ pcntl_signal_dispatch ();
63
+ });
64
+ $ this -> loop -> addTimer ( 0.1 , function () use ( $ check ) {
65
+ $ this ->loop ->cancelTimer ( $ check );
66
+ });
69
67
70
- $ this ->setUpSignalHandler ($ signal );
68
+ $ handled = false ;
69
+ $ this ->assertTrue (pcntl_signal (constant ($ signal ), function () use (&$ handled ) {
70
+ $ handled = true ;
71
+ }));
71
72
72
73
// spawn external process to send signal to current process id
73
74
$ this ->forkSendSignal ($ signal );
75
+
74
76
$ this ->loop ->run ();
75
- $ this ->assertTrue ($ this -> _signalHandled );
77
+ $ this ->assertTrue ($ handled );
76
78
}
77
79
78
80
/**
@@ -86,7 +88,9 @@ public function testSignalInterruptWithStream($signal)
86
88
}
87
89
88
90
// dispatch signal handler every 10ms
89
- $ this ->loop ->addPeriodicTimer (0.01 , function () { pcntl_signal_dispatch (); });
91
+ $ this ->loop ->addPeriodicTimer (0.01 , function () {
92
+ pcntl_signal_dispatch ();
93
+ });
90
94
91
95
// add stream to the loop
92
96
list ($ writeStream , $ readStream ) = $ this ->createSocketPair ();
@@ -97,27 +101,21 @@ public function testSignalInterruptWithStream($signal)
97
101
$ loop ->stop ();
98
102
}
99
103
});
100
- $ this ->loop ->addTimer (0.05 , function () use ($ writeStream ) {
104
+ $ this ->loop ->addTimer (0.1 , function () use ($ writeStream ) {
101
105
fwrite ($ writeStream , "end loop \n" );
102
106
});
103
107
104
- $ this ->setUpSignalHandler ($ signal );
108
+ $ handled = false ;
109
+ $ this ->assertTrue (pcntl_signal (constant ($ signal ), function () use (&$ handled ) {
110
+ $ handled = true ;
111
+ }));
105
112
106
113
// spawn external process to send signal to current process id
107
114
$ this ->forkSendSignal ($ signal );
108
115
109
116
$ this ->loop ->run ();
110
117
111
- $ this ->assertTrue ($ this ->_signalHandled );
112
- }
113
-
114
- /**
115
- * add signal handler for signal
116
- */
117
- protected function setUpSignalHandler ($ signal )
118
- {
119
- $ this ->_signalHandled = false ;
120
- $ this ->assertTrue (pcntl_signal (constant ($ signal ), function () { $ this ->_signalHandled = true ; }));
118
+ $ this ->assertTrue ($ handled );
121
119
}
122
120
123
121
/**
0 commit comments