@@ -167,19 +167,7 @@ def test_create_unix_server_existing_path_sock(self):
167167 srv .close ()
168168 self .loop .run_until_complete (srv .wait_closed ())
169169
170- def test_create_unix_connection_1 (self ):
171- CNT = 0
172- TOTAL_CNT = 100
173-
174- def server (sock ):
175- data = sock .recv_all (4 )
176- self .assertEqual (data , b'AAAA' )
177- sock .send (b'OK' )
178-
179- data = sock .recv_all (4 )
180- self .assertEqual (data , b'BBBB' )
181- sock .send (b'SPAM' )
182-
170+ def test_create_unix_connection_open_unix_con_addr (self ):
183171 async def client (addr ):
184172 reader , writer = await asyncio .open_unix_connection (
185173 addr ,
@@ -191,12 +179,12 @@ async def client(addr):
191179 writer .write (b'BBBB' )
192180 self .assertEqual (await reader .readexactly (4 ), b'SPAM' )
193181
194- nonlocal CNT
195- CNT += 1
196-
197182 writer .close ()
198183
199- async def client_2 (addr ):
184+ self ._test_create_unix_connection_1 (client )
185+
186+ def test_create_unix_connection_open_unix_con_sock (self ):
187+ async def client (addr ):
200188 sock = socket .socket (socket .AF_UNIX )
201189 sock .connect (addr )
202190 reader , writer = await asyncio .open_unix_connection (
@@ -209,12 +197,12 @@ async def client_2(addr):
209197 writer .write (b'BBBB' )
210198 self .assertEqual (await reader .readexactly (4 ), b'SPAM' )
211199
212- nonlocal CNT
213- CNT += 1
214-
215200 writer .close ()
216201
217- async def client_3 (addr ):
202+ self ._test_create_unix_connection_1 (client )
203+
204+ def test_create_unix_connection_open_con_sock (self ):
205+ async def client (addr ):
218206 sock = socket .socket (socket .AF_UNIX )
219207 sock .connect (addr )
220208 reader , writer = await asyncio .open_connection (
@@ -227,11 +215,28 @@ async def client_3(addr):
227215 writer .write (b'BBBB' )
228216 self .assertEqual (await reader .readexactly (4 ), b'SPAM' )
229217
218+ writer .close ()
219+
220+ self ._test_create_unix_connection_1 (client )
221+
222+ def _test_create_unix_connection_1 (self , client ):
223+ CNT = 0
224+ TOTAL_CNT = 100
225+
226+ def server (sock ):
227+ data = sock .recv_all (4 )
228+ self .assertEqual (data , b'AAAA' )
229+ sock .send (b'OK' )
230+
231+ data = sock .recv_all (4 )
232+ self .assertEqual (data , b'BBBB' )
233+ sock .send (b'SPAM' )
234+
235+ async def client_wrapper (addr ):
236+ await client (addr )
230237 nonlocal CNT
231238 CNT += 1
232239
233- writer .close ()
234-
235240 def run (coro ):
236241 nonlocal CNT
237242 CNT = 0
@@ -252,9 +257,7 @@ def run(coro):
252257
253258 self .assertEqual (CNT , TOTAL_CNT )
254259
255- run (client )
256- run (client_2 )
257- run (client_3 )
260+ run (client_wrapper )
258261
259262 def test_create_unix_connection_2 (self ):
260263 with tempfile .NamedTemporaryFile () as tmp :
0 commit comments