fail($message); } return $sockets; } public function testSendReceive() { Loop::run(function () { list($left, $right) = $this->createSockets(); $a = new ChannelledSocket($left, $left); $b = new ChannelledSocket($right, $right); $message = 'hello'; yield $a->send($message); $data = yield $b->receive(); $this->assertSame($message, $data); }); } /** * @depends testSendReceive */ public function testSendReceiveLongData() { Loop::run(function () { list($left, $right) = $this->createSockets(); $a = new ChannelledSocket($left, $left); $b = new ChannelledSocket($right, $right); $length = 0xffff; $message = ''; for ($i = 0; $i < $length; ++$i) { $message .= \chr(\mt_rand(0, 255)); } $a->send($message); $data = yield $b->receive(); $this->assertSame($message, $data); }); } /** * @depends testSendReceive * @expectedException \Amp\Parallel\Sync\ChannelException */ public function testInvalidDataReceived() { Loop::run(function () { list($left, $right) = $this->createSockets(); $a = new ChannelledSocket($left, $left); $b = new ChannelledSocket($right, $right); \fwrite($left, \pack('L', 10) . '1234567890'); $data = yield $b->receive(); }); } /** * @depends testSendReceive * @expectedException \Amp\Parallel\Sync\SerializationException */ public function testSendUnserializableData() { Loop::run(function () { list($left, $right) = $this->createSockets(); $a = new ChannelledSocket($left, $left); $b = new ChannelledSocket($right, $right); // Close $a. $b should close on next read... yield $a->send(function () {}); $data = yield $b->receive(); }); } /** * @depends testSendReceive * @expectedException \Amp\Parallel\Sync\ChannelException */ public function testSendAfterClose() { Loop::run(function () { list($left, $right) = $this->createSockets(); $a = new ChannelledSocket($left, $left); $a->close(); yield $a->send('hello'); }); } /** * @depends testSendReceive * @expectedException \Amp\Parallel\Sync\ChannelException */ public function testReceiveAfterClose() { Loop::run(function () { list($left, $right) = $this->createSockets(); $a = new ChannelledSocket($left, $left); $a->close(); $data = yield $a->receive(); }); } }