Skip to content

Commit ddee079

Browse files
authored
Merge pull request #111 from clue-labs/sigtest
Make signal handling tests more robust and increase test timeouts
2 parents f0117e4 + adf1079 commit ddee079

File tree

1 file changed

+22
-24
lines changed

1 file changed

+22
-24
lines changed

tests/StreamSelectLoopTest.php

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ public function signalProvider()
4747
];
4848
}
4949

50-
private $_signalHandled = false;
51-
5250
/**
5351
* Test signal interrupt when no stream is attached to the loop
5452
* @dataProvider signalProvider
@@ -59,20 +57,24 @@ public function testSignalInterruptNoStream($signal)
5957
$this->markTestSkipped('"pcntl" extension is required to run this test.');
6058
}
6159

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+
});
6967

70-
$this->setUpSignalHandler($signal);
68+
$handled = false;
69+
$this->assertTrue(pcntl_signal(constant($signal), function () use (&$handled) {
70+
$handled = true;
71+
}));
7172

7273
// spawn external process to send signal to current process id
7374
$this->forkSendSignal($signal);
75+
7476
$this->loop->run();
75-
$this->assertTrue($this->_signalHandled);
77+
$this->assertTrue($handled);
7678
}
7779

7880
/**
@@ -86,7 +88,9 @@ public function testSignalInterruptWithStream($signal)
8688
}
8789

8890
// 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+
});
9094

9195
// add stream to the loop
9296
list($writeStream, $readStream) = $this->createSocketPair();
@@ -97,27 +101,21 @@ public function testSignalInterruptWithStream($signal)
97101
$loop->stop();
98102
}
99103
});
100-
$this->loop->addTimer(0.05, function() use ($writeStream) {
104+
$this->loop->addTimer(0.1, function() use ($writeStream) {
101105
fwrite($writeStream, "end loop\n");
102106
});
103107

104-
$this->setUpSignalHandler($signal);
108+
$handled = false;
109+
$this->assertTrue(pcntl_signal(constant($signal), function () use (&$handled) {
110+
$handled = true;
111+
}));
105112

106113
// spawn external process to send signal to current process id
107114
$this->forkSendSignal($signal);
108115

109116
$this->loop->run();
110117

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);
121119
}
122120

123121
/**

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy