ยปCore Development>Code coverage>Lib/test/test_asyncio/test_proactor_events.py

Python code coverage for Lib/test/test_asyncio/test_proactor_events.py

#countcontent
1n/a"""Tests for proactor_events.py"""
2n/a
3n/aimport socket
4n/aimport unittest
5n/afrom unittest import mock
6n/a
7n/aimport asyncio
8n/afrom asyncio.proactor_events import BaseProactorEventLoop
9n/afrom asyncio.proactor_events import _ProactorSocketTransport
10n/afrom asyncio.proactor_events import _ProactorWritePipeTransport
11n/afrom asyncio.proactor_events import _ProactorDuplexPipeTransport
12n/afrom asyncio import test_utils
13n/a
14n/a
15n/adef close_transport(transport):
16n/a # Don't call transport.close() because the event loop and the IOCP proactor
17n/a # are mocked
18n/a if transport._sock is None:
19n/a return
20n/a transport._sock.close()
21n/a transport._sock = None
22n/a
23n/a
24n/aclass ProactorSocketTransportTests(test_utils.TestCase):
25n/a
26n/a def setUp(self):
27n/a super().setUp()
28n/a self.loop = self.new_test_loop()
29n/a self.addCleanup(self.loop.close)
30n/a self.proactor = mock.Mock()
31n/a self.loop._proactor = self.proactor
32n/a self.protocol = test_utils.make_test_protocol(asyncio.Protocol)
33n/a self.sock = mock.Mock(socket.socket)
34n/a
35n/a def socket_transport(self, waiter=None):
36n/a transport = _ProactorSocketTransport(self.loop, self.sock,
37n/a self.protocol, waiter=waiter)
38n/a self.addCleanup(close_transport, transport)
39n/a return transport
40n/a
41n/a def test_ctor(self):
42n/a fut = asyncio.Future(loop=self.loop)
43n/a tr = self.socket_transport(waiter=fut)
44n/a test_utils.run_briefly(self.loop)
45n/a self.assertIsNone(fut.result())
46n/a self.protocol.connection_made(tr)
47n/a self.proactor.recv.assert_called_with(self.sock, 4096)
48n/a
49n/a def test_loop_reading(self):
50n/a tr = self.socket_transport()
51n/a tr._loop_reading()
52n/a self.loop._proactor.recv.assert_called_with(self.sock, 4096)
53n/a self.assertFalse(self.protocol.data_received.called)
54n/a self.assertFalse(self.protocol.eof_received.called)
55n/a
56n/a def test_loop_reading_data(self):
57n/a res = asyncio.Future(loop=self.loop)
58n/a res.set_result(b'data')
59n/a
60n/a tr = self.socket_transport()
61n/a tr._read_fut = res
62n/a tr._loop_reading(res)
63n/a self.loop._proactor.recv.assert_called_with(self.sock, 4096)
64n/a self.protocol.data_received.assert_called_with(b'data')
65n/a
66n/a def test_loop_reading_no_data(self):
67n/a res = asyncio.Future(loop=self.loop)
68n/a res.set_result(b'')
69n/a
70n/a tr = self.socket_transport()
71n/a self.assertRaises(AssertionError, tr._loop_reading, res)
72n/a
73n/a tr.close = mock.Mock()
74n/a tr._read_fut = res
75n/a tr._loop_reading(res)
76n/a self.assertFalse(self.loop._proactor.recv.called)
77n/a self.assertTrue(self.protocol.eof_received.called)
78n/a self.assertTrue(tr.close.called)
79n/a
80n/a def test_loop_reading_aborted(self):
81n/a err = self.loop._proactor.recv.side_effect = ConnectionAbortedError()
82n/a
83n/a tr = self.socket_transport()
84n/a tr._fatal_error = mock.Mock()
85n/a tr._loop_reading()
86n/a tr._fatal_error.assert_called_with(
87n/a err,
88n/a 'Fatal read error on pipe transport')
89n/a
90n/a def test_loop_reading_aborted_closing(self):
91n/a self.loop._proactor.recv.side_effect = ConnectionAbortedError()
92n/a
93n/a tr = self.socket_transport()
94n/a tr._closing = True
95n/a tr._fatal_error = mock.Mock()
96n/a tr._loop_reading()
97n/a self.assertFalse(tr._fatal_error.called)
98n/a
99n/a def test_loop_reading_aborted_is_fatal(self):
100n/a self.loop._proactor.recv.side_effect = ConnectionAbortedError()
101n/a tr = self.socket_transport()
102n/a tr._closing = False
103n/a tr._fatal_error = mock.Mock()
104n/a tr._loop_reading()
105n/a self.assertTrue(tr._fatal_error.called)
106n/a
107n/a def test_loop_reading_conn_reset_lost(self):
108n/a err = self.loop._proactor.recv.side_effect = ConnectionResetError()
109n/a
110n/a tr = self.socket_transport()
111n/a tr._closing = False
112n/a tr._fatal_error = mock.Mock()
113n/a tr._force_close = mock.Mock()
114n/a tr._loop_reading()
115n/a self.assertFalse(tr._fatal_error.called)
116n/a tr._force_close.assert_called_with(err)
117n/a
118n/a def test_loop_reading_exception(self):
119n/a err = self.loop._proactor.recv.side_effect = (OSError())
120n/a
121n/a tr = self.socket_transport()
122n/a tr._fatal_error = mock.Mock()
123n/a tr._loop_reading()
124n/a tr._fatal_error.assert_called_with(
125n/a err,
126n/a 'Fatal read error on pipe transport')
127n/a
128n/a def test_write(self):
129n/a tr = self.socket_transport()
130n/a tr._loop_writing = mock.Mock()
131n/a tr.write(b'data')
132n/a self.assertEqual(tr._buffer, None)
133n/a tr._loop_writing.assert_called_with(data=b'data')
134n/a
135n/a def test_write_no_data(self):
136n/a tr = self.socket_transport()
137n/a tr.write(b'')
138n/a self.assertFalse(tr._buffer)
139n/a
140n/a def test_write_more(self):
141n/a tr = self.socket_transport()
142n/a tr._write_fut = mock.Mock()
143n/a tr._loop_writing = mock.Mock()
144n/a tr.write(b'data')
145n/a self.assertEqual(tr._buffer, b'data')
146n/a self.assertFalse(tr._loop_writing.called)
147n/a
148n/a def test_loop_writing(self):
149n/a tr = self.socket_transport()
150n/a tr._buffer = bytearray(b'data')
151n/a tr._loop_writing()
152n/a self.loop._proactor.send.assert_called_with(self.sock, b'data')
153n/a self.loop._proactor.send.return_value.add_done_callback.\
154n/a assert_called_with(tr._loop_writing)
155n/a
156n/a @mock.patch('asyncio.proactor_events.logger')
157n/a def test_loop_writing_err(self, m_log):
158n/a err = self.loop._proactor.send.side_effect = OSError()
159n/a tr = self.socket_transport()
160n/a tr._fatal_error = mock.Mock()
161n/a tr._buffer = [b'da', b'ta']
162n/a tr._loop_writing()
163n/a tr._fatal_error.assert_called_with(
164n/a err,
165n/a 'Fatal write error on pipe transport')
166n/a tr._conn_lost = 1
167n/a
168n/a tr.write(b'data')
169n/a tr.write(b'data')
170n/a tr.write(b'data')
171n/a tr.write(b'data')
172n/a tr.write(b'data')
173n/a self.assertEqual(tr._buffer, None)
174n/a m_log.warning.assert_called_with('socket.send() raised exception.')
175n/a
176n/a def test_loop_writing_stop(self):
177n/a fut = asyncio.Future(loop=self.loop)
178n/a fut.set_result(b'data')
179n/a
180n/a tr = self.socket_transport()
181n/a tr._write_fut = fut
182n/a tr._loop_writing(fut)
183n/a self.assertIsNone(tr._write_fut)
184n/a
185n/a def test_loop_writing_closing(self):
186n/a fut = asyncio.Future(loop=self.loop)
187n/a fut.set_result(1)
188n/a
189n/a tr = self.socket_transport()
190n/a tr._write_fut = fut
191n/a tr.close()
192n/a tr._loop_writing(fut)
193n/a self.assertIsNone(tr._write_fut)
194n/a test_utils.run_briefly(self.loop)
195n/a self.protocol.connection_lost.assert_called_with(None)
196n/a
197n/a def test_abort(self):
198n/a tr = self.socket_transport()
199n/a tr._force_close = mock.Mock()
200n/a tr.abort()
201n/a tr._force_close.assert_called_with(None)
202n/a
203n/a def test_close(self):
204n/a tr = self.socket_transport()
205n/a tr.close()
206n/a test_utils.run_briefly(self.loop)
207n/a self.protocol.connection_lost.assert_called_with(None)
208n/a self.assertTrue(tr.is_closing())
209n/a self.assertEqual(tr._conn_lost, 1)
210n/a
211n/a self.protocol.connection_lost.reset_mock()
212n/a tr.close()
213n/a test_utils.run_briefly(self.loop)
214n/a self.assertFalse(self.protocol.connection_lost.called)
215n/a
216n/a def test_close_write_fut(self):
217n/a tr = self.socket_transport()
218n/a tr._write_fut = mock.Mock()
219n/a tr.close()
220n/a test_utils.run_briefly(self.loop)
221n/a self.assertFalse(self.protocol.connection_lost.called)
222n/a
223n/a def test_close_buffer(self):
224n/a tr = self.socket_transport()
225n/a tr._buffer = [b'data']
226n/a tr.close()
227n/a test_utils.run_briefly(self.loop)
228n/a self.assertFalse(self.protocol.connection_lost.called)
229n/a
230n/a @mock.patch('asyncio.base_events.logger')
231n/a def test_fatal_error(self, m_logging):
232n/a tr = self.socket_transport()
233n/a tr._force_close = mock.Mock()
234n/a tr._fatal_error(None)
235n/a self.assertTrue(tr._force_close.called)
236n/a self.assertTrue(m_logging.error.called)
237n/a
238n/a def test_force_close(self):
239n/a tr = self.socket_transport()
240n/a tr._buffer = [b'data']
241n/a read_fut = tr._read_fut = mock.Mock()
242n/a write_fut = tr._write_fut = mock.Mock()
243n/a tr._force_close(None)
244n/a
245n/a read_fut.cancel.assert_called_with()
246n/a write_fut.cancel.assert_called_with()
247n/a test_utils.run_briefly(self.loop)
248n/a self.protocol.connection_lost.assert_called_with(None)
249n/a self.assertEqual(None, tr._buffer)
250n/a self.assertEqual(tr._conn_lost, 1)
251n/a
252n/a def test_force_close_idempotent(self):
253n/a tr = self.socket_transport()
254n/a tr._closing = True
255n/a tr._force_close(None)
256n/a test_utils.run_briefly(self.loop)
257n/a self.assertFalse(self.protocol.connection_lost.called)
258n/a
259n/a def test_fatal_error_2(self):
260n/a tr = self.socket_transport()
261n/a tr._buffer = [b'data']
262n/a tr._force_close(None)
263n/a
264n/a test_utils.run_briefly(self.loop)
265n/a self.protocol.connection_lost.assert_called_with(None)
266n/a self.assertEqual(None, tr._buffer)
267n/a
268n/a def test_call_connection_lost(self):
269n/a tr = self.socket_transport()
270n/a tr._call_connection_lost(None)
271n/a self.assertTrue(self.protocol.connection_lost.called)
272n/a self.assertTrue(self.sock.close.called)
273n/a
274n/a def test_write_eof(self):
275n/a tr = self.socket_transport()
276n/a self.assertTrue(tr.can_write_eof())
277n/a tr.write_eof()
278n/a self.sock.shutdown.assert_called_with(socket.SHUT_WR)
279n/a tr.write_eof()
280n/a self.assertEqual(self.sock.shutdown.call_count, 1)
281n/a tr.close()
282n/a
283n/a def test_write_eof_buffer(self):
284n/a tr = self.socket_transport()
285n/a f = asyncio.Future(loop=self.loop)
286n/a tr._loop._proactor.send.return_value = f
287n/a tr.write(b'data')
288n/a tr.write_eof()
289n/a self.assertTrue(tr._eof_written)
290n/a self.assertFalse(self.sock.shutdown.called)
291n/a tr._loop._proactor.send.assert_called_with(self.sock, b'data')
292n/a f.set_result(4)
293n/a self.loop._run_once()
294n/a self.sock.shutdown.assert_called_with(socket.SHUT_WR)
295n/a tr.close()
296n/a
297n/a def test_write_eof_write_pipe(self):
298n/a tr = _ProactorWritePipeTransport(
299n/a self.loop, self.sock, self.protocol)
300n/a self.assertTrue(tr.can_write_eof())
301n/a tr.write_eof()
302n/a self.assertTrue(tr.is_closing())
303n/a self.loop._run_once()
304n/a self.assertTrue(self.sock.close.called)
305n/a tr.close()
306n/a
307n/a def test_write_eof_buffer_write_pipe(self):
308n/a tr = _ProactorWritePipeTransport(self.loop, self.sock, self.protocol)
309n/a f = asyncio.Future(loop=self.loop)
310n/a tr._loop._proactor.send.return_value = f
311n/a tr.write(b'data')
312n/a tr.write_eof()
313n/a self.assertTrue(tr.is_closing())
314n/a self.assertFalse(self.sock.shutdown.called)
315n/a tr._loop._proactor.send.assert_called_with(self.sock, b'data')
316n/a f.set_result(4)
317n/a self.loop._run_once()
318n/a self.loop._run_once()
319n/a self.assertTrue(self.sock.close.called)
320n/a tr.close()
321n/a
322n/a def test_write_eof_duplex_pipe(self):
323n/a tr = _ProactorDuplexPipeTransport(
324n/a self.loop, self.sock, self.protocol)
325n/a self.assertFalse(tr.can_write_eof())
326n/a with self.assertRaises(NotImplementedError):
327n/a tr.write_eof()
328n/a close_transport(tr)
329n/a
330n/a def test_pause_resume_reading(self):
331n/a tr = self.socket_transport()
332n/a futures = []
333n/a for msg in [b'data1', b'data2', b'data3', b'data4', b'']:
334n/a f = asyncio.Future(loop=self.loop)
335n/a f.set_result(msg)
336n/a futures.append(f)
337n/a self.loop._proactor.recv.side_effect = futures
338n/a self.loop._run_once()
339n/a self.assertFalse(tr._paused)
340n/a self.loop._run_once()
341n/a self.protocol.data_received.assert_called_with(b'data1')
342n/a self.loop._run_once()
343n/a self.protocol.data_received.assert_called_with(b'data2')
344n/a tr.pause_reading()
345n/a self.assertTrue(tr._paused)
346n/a for i in range(10):
347n/a self.loop._run_once()
348n/a self.protocol.data_received.assert_called_with(b'data2')
349n/a tr.resume_reading()
350n/a self.assertFalse(tr._paused)
351n/a self.loop._run_once()
352n/a self.protocol.data_received.assert_called_with(b'data3')
353n/a self.loop._run_once()
354n/a self.protocol.data_received.assert_called_with(b'data4')
355n/a tr.close()
356n/a
357n/a
358n/a def pause_writing_transport(self, high):
359n/a tr = self.socket_transport()
360n/a tr.set_write_buffer_limits(high=high)
361n/a
362n/a self.assertEqual(tr.get_write_buffer_size(), 0)
363n/a self.assertFalse(self.protocol.pause_writing.called)
364n/a self.assertFalse(self.protocol.resume_writing.called)
365n/a return tr
366n/a
367n/a def test_pause_resume_writing(self):
368n/a tr = self.pause_writing_transport(high=4)
369n/a
370n/a # write a large chunk, must pause writing
371n/a fut = asyncio.Future(loop=self.loop)
372n/a self.loop._proactor.send.return_value = fut
373n/a tr.write(b'large data')
374n/a self.loop._run_once()
375n/a self.assertTrue(self.protocol.pause_writing.called)
376n/a
377n/a # flush the buffer
378n/a fut.set_result(None)
379n/a self.loop._run_once()
380n/a self.assertEqual(tr.get_write_buffer_size(), 0)
381n/a self.assertTrue(self.protocol.resume_writing.called)
382n/a
383n/a def test_pause_writing_2write(self):
384n/a tr = self.pause_writing_transport(high=4)
385n/a
386n/a # first short write, the buffer is not full (3 <= 4)
387n/a fut1 = asyncio.Future(loop=self.loop)
388n/a self.loop._proactor.send.return_value = fut1
389n/a tr.write(b'123')
390n/a self.loop._run_once()
391n/a self.assertEqual(tr.get_write_buffer_size(), 3)
392n/a self.assertFalse(self.protocol.pause_writing.called)
393n/a
394n/a # fill the buffer, must pause writing (6 > 4)
395n/a tr.write(b'abc')
396n/a self.loop._run_once()
397n/a self.assertEqual(tr.get_write_buffer_size(), 6)
398n/a self.assertTrue(self.protocol.pause_writing.called)
399n/a
400n/a def test_pause_writing_3write(self):
401n/a tr = self.pause_writing_transport(high=4)
402n/a
403n/a # first short write, the buffer is not full (1 <= 4)
404n/a fut = asyncio.Future(loop=self.loop)
405n/a self.loop._proactor.send.return_value = fut
406n/a tr.write(b'1')
407n/a self.loop._run_once()
408n/a self.assertEqual(tr.get_write_buffer_size(), 1)
409n/a self.assertFalse(self.protocol.pause_writing.called)
410n/a
411n/a # second short write, the buffer is not full (3 <= 4)
412n/a tr.write(b'23')
413n/a self.loop._run_once()
414n/a self.assertEqual(tr.get_write_buffer_size(), 3)
415n/a self.assertFalse(self.protocol.pause_writing.called)
416n/a
417n/a # fill the buffer, must pause writing (6 > 4)
418n/a tr.write(b'abc')
419n/a self.loop._run_once()
420n/a self.assertEqual(tr.get_write_buffer_size(), 6)
421n/a self.assertTrue(self.protocol.pause_writing.called)
422n/a
423n/a def test_dont_pause_writing(self):
424n/a tr = self.pause_writing_transport(high=4)
425n/a
426n/a # write a large chunk which completes immedialty,
427n/a # it should not pause writing
428n/a fut = asyncio.Future(loop=self.loop)
429n/a fut.set_result(None)
430n/a self.loop._proactor.send.return_value = fut
431n/a tr.write(b'very large data')
432n/a self.loop._run_once()
433n/a self.assertEqual(tr.get_write_buffer_size(), 0)
434n/a self.assertFalse(self.protocol.pause_writing.called)
435n/a
436n/a
437n/aclass BaseProactorEventLoopTests(test_utils.TestCase):
438n/a
439n/a def setUp(self):
440n/a super().setUp()
441n/a
442n/a self.sock = test_utils.mock_nonblocking_socket()
443n/a self.proactor = mock.Mock()
444n/a
445n/a self.ssock, self.csock = mock.Mock(), mock.Mock()
446n/a
447n/a class EventLoop(BaseProactorEventLoop):
448n/a def _socketpair(s):
449n/a return (self.ssock, self.csock)
450n/a
451n/a self.loop = EventLoop(self.proactor)
452n/a self.set_event_loop(self.loop)
453n/a
454n/a @mock.patch.object(BaseProactorEventLoop, 'call_soon')
455n/a @mock.patch.object(BaseProactorEventLoop, '_socketpair')
456n/a def test_ctor(self, socketpair, call_soon):
457n/a ssock, csock = socketpair.return_value = (
458n/a mock.Mock(), mock.Mock())
459n/a loop = BaseProactorEventLoop(self.proactor)
460n/a self.assertIs(loop._ssock, ssock)
461n/a self.assertIs(loop._csock, csock)
462n/a self.assertEqual(loop._internal_fds, 1)
463n/a call_soon.assert_called_with(loop._loop_self_reading)
464n/a loop.close()
465n/a
466n/a def test_close_self_pipe(self):
467n/a self.loop._close_self_pipe()
468n/a self.assertEqual(self.loop._internal_fds, 0)
469n/a self.assertTrue(self.ssock.close.called)
470n/a self.assertTrue(self.csock.close.called)
471n/a self.assertIsNone(self.loop._ssock)
472n/a self.assertIsNone(self.loop._csock)
473n/a
474n/a # Don't call close(): _close_self_pipe() cannot be called twice
475n/a self.loop._closed = True
476n/a
477n/a def test_close(self):
478n/a self.loop._close_self_pipe = mock.Mock()
479n/a self.loop.close()
480n/a self.assertTrue(self.loop._close_self_pipe.called)
481n/a self.assertTrue(self.proactor.close.called)
482n/a self.assertIsNone(self.loop._proactor)
483n/a
484n/a self.loop._close_self_pipe.reset_mock()
485n/a self.loop.close()
486n/a self.assertFalse(self.loop._close_self_pipe.called)
487n/a
488n/a def test_sock_recv(self):
489n/a self.loop.sock_recv(self.sock, 1024)
490n/a self.proactor.recv.assert_called_with(self.sock, 1024)
491n/a
492n/a def test_sock_sendall(self):
493n/a self.loop.sock_sendall(self.sock, b'data')
494n/a self.proactor.send.assert_called_with(self.sock, b'data')
495n/a
496n/a def test_sock_connect(self):
497n/a self.loop.sock_connect(self.sock, ('1.2.3.4', 123))
498n/a self.proactor.connect.assert_called_with(self.sock, ('1.2.3.4', 123))
499n/a
500n/a def test_sock_accept(self):
501n/a self.loop.sock_accept(self.sock)
502n/a self.proactor.accept.assert_called_with(self.sock)
503n/a
504n/a def test_socketpair(self):
505n/a class EventLoop(BaseProactorEventLoop):
506n/a # override the destructor to not log a ResourceWarning
507n/a def __del__(self):
508n/a pass
509n/a self.assertRaises(
510n/a NotImplementedError, EventLoop, self.proactor)
511n/a
512n/a def test_make_socket_transport(self):
513n/a tr = self.loop._make_socket_transport(self.sock, asyncio.Protocol())
514n/a self.assertIsInstance(tr, _ProactorSocketTransport)
515n/a close_transport(tr)
516n/a
517n/a def test_loop_self_reading(self):
518n/a self.loop._loop_self_reading()
519n/a self.proactor.recv.assert_called_with(self.ssock, 4096)
520n/a self.proactor.recv.return_value.add_done_callback.assert_called_with(
521n/a self.loop._loop_self_reading)
522n/a
523n/a def test_loop_self_reading_fut(self):
524n/a fut = mock.Mock()
525n/a self.loop._loop_self_reading(fut)
526n/a self.assertTrue(fut.result.called)
527n/a self.proactor.recv.assert_called_with(self.ssock, 4096)
528n/a self.proactor.recv.return_value.add_done_callback.assert_called_with(
529n/a self.loop._loop_self_reading)
530n/a
531n/a def test_loop_self_reading_exception(self):
532n/a self.loop.close = mock.Mock()
533n/a self.loop.call_exception_handler = mock.Mock()
534n/a self.proactor.recv.side_effect = OSError()
535n/a self.loop._loop_self_reading()
536n/a self.assertTrue(self.loop.call_exception_handler.called)
537n/a
538n/a def test_write_to_self(self):
539n/a self.loop._write_to_self()
540n/a self.csock.send.assert_called_with(b'\0')
541n/a
542n/a def test_process_events(self):
543n/a self.loop._process_events([])
544n/a
545n/a @mock.patch('asyncio.base_events.logger')
546n/a def test_create_server(self, m_log):
547n/a pf = mock.Mock()
548n/a call_soon = self.loop.call_soon = mock.Mock()
549n/a
550n/a self.loop._start_serving(pf, self.sock)
551n/a self.assertTrue(call_soon.called)
552n/a
553n/a # callback
554n/a loop = call_soon.call_args[0][0]
555n/a loop()
556n/a self.proactor.accept.assert_called_with(self.sock)
557n/a
558n/a # conn
559n/a fut = mock.Mock()
560n/a fut.result.return_value = (mock.Mock(), mock.Mock())
561n/a
562n/a make_tr = self.loop._make_socket_transport = mock.Mock()
563n/a loop(fut)
564n/a self.assertTrue(fut.result.called)
565n/a self.assertTrue(make_tr.called)
566n/a
567n/a # exception
568n/a fut.result.side_effect = OSError()
569n/a loop(fut)
570n/a self.assertTrue(self.sock.close.called)
571n/a self.assertTrue(m_log.error.called)
572n/a
573n/a def test_create_server_cancel(self):
574n/a pf = mock.Mock()
575n/a call_soon = self.loop.call_soon = mock.Mock()
576n/a
577n/a self.loop._start_serving(pf, self.sock)
578n/a loop = call_soon.call_args[0][0]
579n/a
580n/a # cancelled
581n/a fut = asyncio.Future(loop=self.loop)
582n/a fut.cancel()
583n/a loop(fut)
584n/a self.assertTrue(self.sock.close.called)
585n/a
586n/a def test_stop_serving(self):
587n/a sock = mock.Mock()
588n/a self.loop._stop_serving(sock)
589n/a self.assertTrue(sock.close.called)
590n/a self.proactor._stop_serving.assert_called_with(sock)
591n/a
592n/a
593n/aif __name__ == '__main__':
594n/a unittest.main()