Skip to content

Commit fcba4ad

Browse files
committed
Add test for weak types
1 parent f7f5a9a commit fcba4ad

File tree

1 file changed

+49
-2
lines changed

1 file changed

+49
-2
lines changed

src/Test.php

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,50 @@ function provideRegistrationArgs()
207207
return $args;
208208
}
209209

210+
/** @dataProvider provideRegistrationArgs */
211+
function testWeakTypes($type, $args) {
212+
$this->start(function (Driver $loop) use ($type, $args, &$invoked) {
213+
if ($type == "onReadable") {
214+
$ends = stream_socket_pair(\stripos(PHP_OS, "win") === 0 ? STREAM_PF_INET : STREAM_PF_UNIX, STREAM_SOCK_STREAM, STREAM_IPPROTO_IP);
215+
fwrite($ends[0], "trigger readability watcher");
216+
$args = [$ends[1]];
217+
} else {
218+
array_pop($args);
219+
}
220+
221+
$expectedData = 20.75;
222+
if (substr($type, 0, 2) == "on") {
223+
$args[] = function($watcherId, $arg, int $data) use ($loop, &$invoked, $expectedData) {
224+
$invoked = true;
225+
$this->assertSame((int) $expectedData, $data);
226+
$loop->unreference($watcherId);
227+
};
228+
} else {
229+
$args[] = function($watcherId, int $data) use ($loop, &$invoked, $expectedData, $type) {
230+
$invoked = true;
231+
$this->assertSame((int) $expectedData, $data);
232+
if ($type == "repeat") {
233+
$loop->unreference($watcherId);
234+
}
235+
};
236+
}
237+
$args[] = $expectedData;
238+
call_user_func_array([$loop, $type], $args);
239+
240+
if ($type == "onSignal") {
241+
$this->testSignalCapability();
242+
if (!\extension_loaded("posix")) {
243+
$this->markTestSkipped("ext/posix required to test signal handlers");
244+
}
245+
$loop->defer(function() {
246+
\posix_kill(\getmypid(), \SIGUSR1);
247+
});
248+
}
249+
});
250+
251+
$this->assertTrue($invoked);
252+
}
253+
210254
/** @dataProvider provideRegistrationArgs */
211255
function testDisableWithConsecutiveCancel($type, $args)
212256
{
@@ -360,13 +404,16 @@ function testWatcherRegistrationAndCancellationInfo($type, $args)
360404
function testNoMemoryLeak($type, $args)
361405
{
362406
if ($this->getTestResultObject()->getCollectCodeCoverageInformation()) {
363-
$this->markTestSkipped("Cannot run this test with code coverage active [code coverage consumes memory which makes it impossible to rely on memory_get_usage()]");
364-
}
407+
$this->markTestSkipped("Cannot run this test with code coverage active [code coverage consumes memory which makes it impossible to rely on memory_get_usage()]");
408+
}
365409

366410
$runs = 2000;
367411

368412
if ($type === "onSignal") {
369413
$this->testSignalCapability();
414+
if (!\extension_loaded("posix")) {
415+
$this->markTestSkipped("ext/posix required to test signal handlers");
416+
}
370417
}
371418

372419
$this->start(function(Driver $loop) use ($type, $args, $runs) {

0 commit comments

Comments
 (0)