Skip to content

Commit

Permalink
Test loop implementations to keep track of stream resources (refcount)
Browse files Browse the repository at this point in the history
  • Loading branch information
clue committed Dec 1, 2017
1 parent 61e3e65 commit 04f7ca6
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions tests/AbstractLoopTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,39 @@ public function testAddReadStreamIgnoresSecondCallable()
$this->tickLoop($this->loop);
}

public function testAddReadStreamReceivesDataFromStreamReference()
{
$this->received = '';
$this->subAddReadStreamReceivesDataFromStreamReference();
$this->assertEquals('', $this->received);

$this->assertRunFasterThan($this->tickTimeout * 2);
$this->assertEquals('[hello]X', $this->received);
}

/**
* Telper for above test. This happens in another helper method to verify
* the loop keep track of assigned stream resources (refcount).
*/
private function subAddReadStreamReceivesDataFromStreamReference()
{
list ($input, $output) = $this->createSocketPair();

fwrite($input, 'hello');
fclose($input);

$this->loop->addReadStream($output, function ($output) {
$chunk = fread($output, 1024);
if ($chunk === '') {
$this->received .= 'X';
$this->loop->removeReadStream($output);
fclose($output);
} else {
$this->received .= '[' . $chunk . ']';
}
});
}

public function testAddWriteStream()
{
list ($input) = $this->createSocketPair();
Expand Down

0 comments on commit 04f7ca6

Please sign in to comment.