-
-
Notifications
You must be signed in to change notification settings - Fork 129
/
Copy pathExtEventLoopTest.php
89 lines (68 loc) · 2.41 KB
/
ExtEventLoopTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
namespace React\Tests\EventLoop;
use React\EventLoop\ExtEventLoop;
class ExtEventLoopTest extends AbstractLoopTest
{
/** @var ?string */
private $fifoPath;
public function createLoop($readStreamCompatible = false)
{
if ('Linux' === PHP_OS && !extension_loaded('posix')) {
$this->markTestSkipped('libevent tests skipped on linux due to linux epoll issues.');
}
if (!extension_loaded('event')) {
$this->markTestSkipped('ext-event tests skipped because ext-event is not installed.');
}
return new ExtEventLoop();
}
/**
* @after
*/
public function tearDownFile()
{
if ($this->fifoPath !== null && file_exists($this->fifoPath)) {
unlink($this->fifoPath);
}
}
public function createStream()
{
// Use a FIFO on linux to get around lack of support for disk-based file
// descriptors when using the EPOLL back-end.
if ('Linux' === PHP_OS) {
$this->fifoPath = tempnam(sys_get_temp_dir(), 'react-');
assert(is_string($this->fifoPath));
unlink($this->fifoPath);
posix_mkfifo($this->fifoPath, 0600);
$stream = fopen($this->fifoPath, 'r+');
// ext-event (as of 1.8.1) does not yet support in-memory temporary
// streams. Setting maxmemory:0 and performing a write forces PHP to
// back this temporary stream with a real file.
//
// This problem is mentioned at https://bugs.php.net/bug.php?id=64652&edit=3
// but remains unresolved (despite that issue being closed).
} else {
$stream = fopen('php://temp/maxmemory:0', 'r+');
fwrite($stream, 'x');
ftruncate($stream, 0);
}
return $stream;
}
/**
* @group epoll-readable-error
*/
public function testCanUseReadableStreamWithFeatureFds()
{
if (PHP_VERSION_ID > 70000) {
$this->markTestSkipped('Memory stream not supported');
}
$this->loop = $this->createLoop(true);
$input = fopen('php://temp/maxmemory:0', 'r+');
fwrite($input, 'x');
ftruncate($input, 0);
$this->loop->addReadStream($input, $this->expectCallableExactly(2));
fwrite($input, "foo\n");
$this->tickLoop($this->loop);
fwrite($input, "bar\n");
$this->tickLoop($this->loop);
}
}