File tree 3 files changed +15
-14
lines changed 3 files changed +15
-14
lines changed Original file line number Diff line number Diff line change @@ -53,6 +53,7 @@ public function __construct(int $timeout)
53
53
*
54
54
* @return T
55
55
*
56
+ * @throws \Throwable
56
57
* @throws DeadlineException Running the code hit the deadline
57
58
* @throws LockAcquireException Installing the timeout failed
58
59
*/
@@ -67,7 +68,7 @@ public function timeBoxed(callable $code)
67
68
));
68
69
});
69
70
if (!$ signal ) {
70
- throw new LockAcquireException ('Could not install signal ' );
71
+ throw new LockAcquireException ('Could not install signal handler ' );
71
72
}
72
73
73
74
$ oldAlarm = pcntl_alarm ($ this ->timeout );
@@ -79,8 +80,11 @@ public function timeBoxed(callable $code)
79
80
return $ code ();
80
81
} finally {
81
82
pcntl_alarm (0 );
82
- pcntl_signal_dispatch ();
83
- pcntl_signal (\SIGALRM , $ existingHandler );
83
+ try {
84
+ pcntl_signal_dispatch ();
85
+ } finally {
86
+ pcntl_signal (\SIGALRM , $ existingHandler );
87
+ }
84
88
}
85
89
}
86
90
Original file line number Diff line number Diff line change @@ -46,7 +46,6 @@ public function testInvalidAcquireTimeout(float $acquireTimeout): void
46
46
47
47
$ this ->expectException (\InvalidArgumentException::class);
48
48
$ this ->expectExceptionMessage ('The lock acquire timeout must be greater than or equal to 0.0 ( ' . LockUtil::getInstance ()->formatTimeout ($ acquireTimeout ) . ' was given) ' );
49
-
50
49
$ loop ->execute (static function () {
51
50
self ::fail ();
52
51
}, $ acquireTimeout );
@@ -78,10 +77,10 @@ public function testExecutionWithinAcquireTimeout(): void
78
77
79
78
public function testExecutionWithinAcquireTimeoutWithoutCallingEnd (): void
80
79
{
80
+ $ loop = new Loop ();
81
+
81
82
$ this ->expectException (LockAcquireTimeoutException::class);
82
83
$ this ->expectExceptionMessage ('Lock acquire timeout of 0.5 seconds has been exceeded ' );
83
-
84
- $ loop = new Loop ();
85
84
$ loop ->execute (static function () {
86
85
usleep (10 * 1000 );
87
86
}, 0.5 );
@@ -102,20 +101,20 @@ public function testExceedAcquireTimeoutIsAcceptableIfEndWasCalled(): void
102
101
103
102
public function testExceedAcquireTimeoutWithoutCallingEnd (): void
104
103
{
104
+ $ loop = new Loop ();
105
+
105
106
$ this ->expectException (LockAcquireTimeoutException::class);
106
107
$ this ->expectExceptionMessage ('Lock acquire timeout of 0.5 seconds has been exceeded ' );
107
-
108
- $ loop = new Loop ();
109
108
$ loop ->execute (static function () {
110
109
usleep (501 * 1000 );
111
110
}, 0.5 );
112
111
}
113
112
114
113
public function testExceptionStopsIteration (): void
115
114
{
116
- $ this ->expectException (\DomainException::class);
117
-
118
115
$ loop = new Loop ();
116
+
117
+ $ this ->expectException (\DomainException::class);
119
118
$ loop ->execute (static function () {
120
119
throw new \DomainException ();
121
120
}, 1 );
Original file line number Diff line number Diff line change @@ -21,10 +21,9 @@ class PcntlTimeoutTest extends TestCase
21
21
*/
22
22
public function testShouldTimeout (): void
23
23
{
24
- $ this ->expectException (DeadlineException::class);
25
-
26
24
$ timeout = new PcntlTimeout (1 );
27
25
26
+ $ this ->expectException (DeadlineException::class);
28
27
$ timeout ->timeBoxed (static function () {
29
28
sleep (2 );
30
29
});
@@ -49,12 +48,11 @@ public function testShouldNotTimeout(): void
49
48
*/
50
49
public function testShouldFailOnExistingAlarm (): void
51
50
{
52
- $ this ->expectException (LockAcquireException::class);
53
-
54
51
try {
55
52
pcntl_alarm (1 );
56
53
$ timeout = new PcntlTimeout (1 );
57
54
55
+ $ this ->expectException (LockAcquireException::class);
58
56
$ timeout ->timeBoxed (static function () {
59
57
sleep (1 );
60
58
});
You can’t perform that action at this time.
0 commit comments