|
4 | 4 |
|
5 | 5 | use React\MySQL\Connection; |
6 | 6 | use React\MySQL\Exception; |
| 7 | +use React\Socket\Server; |
7 | 8 |
|
8 | 9 | class ConnectionTest extends BaseTestCase |
9 | 10 | { |
@@ -111,6 +112,59 @@ public function testCloseWhileConnectingWillBeQueuedAfterConnection() |
111 | 112 | $loop->run(); |
112 | 113 | } |
113 | 114 |
|
| 115 | + public function testPingAfterConnectWillEmitErrorWhenServerClosesConnection() |
| 116 | + { |
| 117 | + $this->expectOutputString('Connection lost'); |
| 118 | + |
| 119 | + $loop = \React\EventLoop\Factory::create(); |
| 120 | + |
| 121 | + $server = new Server(0, $loop); |
| 122 | + $server->on('connection', function ($connection) use ($server) { |
| 123 | + $server->close(); |
| 124 | + $connection->close(); |
| 125 | + }); |
| 126 | + |
| 127 | + $parts = parse_url($server->getAddress()); |
| 128 | + $options = $this->getConnectionOptions(); |
| 129 | + $options['host'] = $parts['host']; |
| 130 | + $options['port'] = $parts['port']; |
| 131 | + |
| 132 | + $conn = new Connection($loop, $options); |
| 133 | + |
| 134 | + $conn->connect(function ($err) { |
| 135 | + echo $err ? $err->getMessage() : 'OK'; |
| 136 | + }); |
| 137 | + |
| 138 | + $loop->run(); |
| 139 | + } |
| 140 | + |
| 141 | + public function testConnectWillEmitErrorWhenServerClosesConnection() |
| 142 | + { |
| 143 | + $this->expectOutputString('Connection lost'); |
| 144 | + |
| 145 | + $loop = \React\EventLoop\Factory::create(); |
| 146 | + |
| 147 | + $server = new Server(0, $loop); |
| 148 | + $server->on('connection', function ($connection) use ($server) { |
| 149 | + $server->close(); |
| 150 | + $connection->close(); |
| 151 | + }); |
| 152 | + |
| 153 | + $parts = parse_url($server->getAddress()); |
| 154 | + $options = $this->getConnectionOptions(); |
| 155 | + $options['host'] = $parts['host']; |
| 156 | + $options['port'] = $parts['port']; |
| 157 | + |
| 158 | + $conn = new Connection($loop, $options); |
| 159 | + |
| 160 | + $conn->connect(function () { }); |
| 161 | + $conn->ping(function ($err) { |
| 162 | + echo $err ? $err->getMessage() : 'OK'; |
| 163 | + }); |
| 164 | + |
| 165 | + $loop->run(); |
| 166 | + } |
| 167 | + |
114 | 168 | public function testPingAndCloseWhileConnectingWillBeQueuedAfterConnection() |
115 | 169 | { |
116 | 170 | $this->expectOutputString('connectedpingclosed'); |
|
0 commit comments