| 260 | self.assertTrue(tr.close.called) |
| 261 | |
| 262 | def test_connect(self): |
| 263 | tr, proto = unittest.mock.Mock(), unittest.mock.Mock() |
| 264 | proto.is_connected.return_value = True |
| 265 | |
| 266 | class Req: |
| 267 | host = 'host' |
| 268 | port = 80 |
| 269 | ssl = False |
| 270 | response = unittest.mock.Mock() |
| 271 | |
| 272 | conn = aiohttp.BaseConnector(loop=self.loop) |
| 273 | key = ('host', 80, False) |
| 274 | conn._conns[key] = [(tr, proto, self.loop.time())] |
| 275 | conn._create_connection = unittest.mock.Mock() |
| 276 | conn._create_connection.return_value = asyncio.Future(loop=self.loop) |
| 277 | conn._create_connection.return_value.set_result((tr, proto)) |
| 278 | |
| 279 | connection = self.loop.run_until_complete(conn.connect(Req())) |
| 280 | self.assertFalse(conn._create_connection.called) |
| 281 | self.assertEqual(connection._transport, tr) |
| 282 | self.assertEqual(connection._protocol, proto) |
| 283 | self.assertIsInstance(connection, Connection) |
| 284 | connection.close() |
| 285 | |
| 286 | def test_connect_timeout(self): |
| 287 | conn = aiohttp.BaseConnector(loop=self.loop) |