public function testDataWillBeEmittedInMultipleChunksWhenClientSendsExcessiveAmounts()
{
$client = stream_socket_client('tcp://localhost:' . $this->port);
$stream = new Stream($client, $this->loop);
$bytes = 1024 * 1024;
$stream->end(str_repeat('*', $bytes));
$mock = $this->expectCallableOnce();
// explicitly unset server because we only accept a single connection
// and then already call shutdown()
$server = $this->server;
$this->server = null;
$received = 0;
$server->on('connection', function ($conn) use($mock, &$received, $server) {
// count number of bytes received
$conn->on('data', function ($data) use(&$received) {
$received += strlen($data);
});
$conn->on('end', $mock);
// do not await any further connections in order to let the loop terminate
$server->shutdown();
});
$this->loop->run();
$this->assertEquals($bytes, $received);
}