self.run_loop(self.loop.sock_connect(sock, (support.HOST, port)))
def cleanup():
- proto.transport.close()
- self.run_loop(proto.wait_closed())
+ if proto.transport is not None:
+ # can be None if the task was cancelled before
+ # connection_made callback
+ proto.transport.close()
+ self.run_loop(proto.wait_closed())
server.close()
self.run_loop(server.wait_closed())
return sock, proto
- def test_success(self):
+ def test_sock_sendfile_success(self):
sock, proto = self.prepare()
ret = self.run_loop(self.loop.sock_sendfile(sock, self.file))
sock.close()
self.assertEqual(proto.data, self.DATA)
self.assertEqual(self.file.tell(), len(self.DATA))
- def test_with_offset_and_count(self):
+ def test_sock_sendfile_with_offset_and_count(self):
sock, proto = self.prepare()
ret = self.run_loop(self.loop.sock_sendfile(sock, self.file,
1000, 2000))
self.assertEqual(self.file.tell(), 3000)
self.assertEqual(ret, 2000)
- def test_sendfile_not_available(self):
+ def test_sock_sendfile_not_available(self):
sock, proto = self.prepare()
with mock.patch('asyncio.unix_events.os', spec=[]):
with self.assertRaisesRegex(events.SendfileNotAvailableError,
0, None))
self.assertEqual(self.file.tell(), 0)
- def test_sendfile_not_a_file(self):
+ def test_sock_sendfile_not_a_file(self):
sock, proto = self.prepare()
f = object()
with self.assertRaisesRegex(events.SendfileNotAvailableError,
0, None))
self.assertEqual(self.file.tell(), 0)
- def test_sendfile_iobuffer(self):
+ def test_sock_sendfile_iobuffer(self):
sock, proto = self.prepare()
f = io.BytesIO()
with self.assertRaisesRegex(events.SendfileNotAvailableError,
0, None))
self.assertEqual(self.file.tell(), 0)
- def test_sendfile_not_regular_file(self):
+ def test_sock_sendfile_not_regular_file(self):
sock, proto = self.prepare()
f = mock.Mock()
f.fileno.return_value = -1
0, None))
self.assertEqual(self.file.tell(), 0)
- def test_sendfile_zero_size(self):
+ def test_sock_sendfile_zero_size(self):
sock, proto = self.prepare()
fname = support.TESTFN + '.suffix'
with open(fname, 'wb') as f:
self.assertEqual(ret, 0)
self.assertEqual(self.file.tell(), 0)
- def test_mix_sendfile_and_regular_send(self):
+ def test_sock_sendfile_mix_with_regular_send(self):
buf = b'1234567890' * 1024 * 1024 # 10 MB
sock, proto = self.prepare()
self.run_loop(self.loop.sock_sendall(sock, buf))
self.assertEqual(proto.data, expected)
self.assertEqual(self.file.tell(), len(self.DATA))
- def test_cancel1(self):
+ def test_sock_sendfile_cancel1(self):
sock, proto = self.prepare()
fut = self.loop.create_future()
with self.assertRaises(KeyError):
self.loop._selector.get_key(sock)
- def test_cancel2(self):
+ def test_sock_sendfile_cancel2(self):
sock, proto = self.prepare()
fut = self.loop.create_future()
with self.assertRaises(KeyError):
self.loop._selector.get_key(sock)
- def test_blocking_error(self):
+ def test_sock_sendfile_blocking_error(self):
sock, proto = self.prepare()
fileno = self.file.fileno()
self.assertIsNotNone(key)
fut.add_done_callback.assert_called_once_with(mock.ANY)
- def test_os_error_first_call(self):
+ def test_sock_sendfile_os_error_first_call(self):
sock, proto = self.prepare()
fileno = self.file.fileno()
self.assertIsInstance(exc, events.SendfileNotAvailableError)
self.assertEqual(0, self.file.tell())
- def test_os_error_next_call(self):
+ def test_sock_sendfile_os_error_next_call(self):
sock, proto = self.prepare()
fileno = self.file.fileno()
self.assertIs(exc, err)
self.assertEqual(1000, self.file.tell())
- def test_exception(self):
+ def test_sock_sendfile_exception(self):
sock, proto = self.prepare()
fileno = self.file.fileno()