Skip to content

Commit 04f7ca6

Browse files
committed
Test loop implementations to keep track of stream resources (refcount)
1 parent 61e3e65 commit 04f7ca6

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

tests/AbstractLoopTest.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,39 @@ public function testAddReadStreamIgnoresSecondCallable()
6161
$this->tickLoop($this->loop);
6262
}
6363

64+
public function testAddReadStreamReceivesDataFromStreamReference()
65+
{
66+
$this->received = '';
67+
$this->subAddReadStreamReceivesDataFromStreamReference();
68+
$this->assertEquals('', $this->received);
69+
70+
$this->assertRunFasterThan($this->tickTimeout * 2);
71+
$this->assertEquals('[hello]X', $this->received);
72+
}
73+
74+
/**
75+
* Telper for above test. This happens in another helper method to verify
76+
* the loop keep track of assigned stream resources (refcount).
77+
*/
78+
private function subAddReadStreamReceivesDataFromStreamReference()
79+
{
80+
list ($input, $output) = $this->createSocketPair();
81+
82+
fwrite($input, 'hello');
83+
fclose($input);
84+
85+
$this->loop->addReadStream($output, function ($output) {
86+
$chunk = fread($output, 1024);
87+
if ($chunk === '') {
88+
$this->received .= 'X';
89+
$this->loop->removeReadStream($output);
90+
fclose($output);
91+
} else {
92+
$this->received .= '[' . $chunk . ']';
93+
}
94+
});
95+
}
96+
6497
public function testAddWriteStream()
6598
{
6699
list ($input) = $this->createSocketPair();

0 commit comments

Comments
 (0)