MCPcopy Index your code
hub / github.com/python/cpython / test_wait_closed_basic

Method test_wait_closed_basic

Lib/test/test_asyncio/test_server.py:127–166  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

125class TestServer2(unittest.IsolatedAsyncioTestCase):
126
127 async def test_wait_closed_basic(self):
128 async def serve(rd, wr):
129 try:
130 await rd.read()
131 finally:
132 wr.close()
133 await wr.wait_closed()
134
135 srv = await asyncio.start_server(serve, socket_helper.HOSTv4, 0)
136 self.addCleanup(srv.close)
137
138 # active count = 0, not closed: should block
139 task1 = asyncio.create_task(srv.wait_closed())
140 await asyncio.sleep(0)
141 self.assertFalse(task1.done())
142
143 # active count != 0, not closed: should block
144 addr = srv.sockets[0].getsockname()
145 (rd, wr) = await asyncio.open_connection(addr[0], addr[1])
146 task2 = asyncio.create_task(srv.wait_closed())
147 await asyncio.sleep(0)
148 self.assertFalse(task1.done())
149 self.assertFalse(task2.done())
150
151 srv.close()
152 await asyncio.sleep(0)
153 # active count != 0, closed: should block
154 task3 = asyncio.create_task(srv.wait_closed())
155 await asyncio.sleep(0)
156 self.assertFalse(task1.done())
157 self.assertFalse(task2.done())
158 self.assertFalse(task3.done())
159
160 wr.close()
161 await wr.wait_closed()
162 # active count == 0, closed: should unblock
163 await task1
164 await task2
165 await task3
166 await srv.wait_closed() # Return immediately
167
168 async def test_wait_closed_race(self):
169 # Test a regression in 3.12.0, should be fixed in 3.12.1

Callers

nothing calls this directly

Calls 9

addCleanupMethod · 0.80
assertFalseMethod · 0.80
start_serverMethod · 0.45
create_taskMethod · 0.45
wait_closedMethod · 0.45
sleepMethod · 0.45
doneMethod · 0.45
getsocknameMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected