@@ -167,19 +167,7 @@ def test_create_unix_server_existing_path_sock(self):
167
167
srv .close ()
168
168
self .loop .run_until_complete (srv .wait_closed ())
169
169
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 ):
183
171
async def client (addr ):
184
172
reader , writer = await asyncio .open_unix_connection (
185
173
addr ,
@@ -191,12 +179,12 @@ async def client(addr):
191
179
writer .write (b'BBBB' )
192
180
self .assertEqual (await reader .readexactly (4 ), b'SPAM' )
193
181
194
- nonlocal CNT
195
- CNT += 1
196
-
197
182
writer .close ()
198
183
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 ):
200
188
sock = socket .socket (socket .AF_UNIX )
201
189
sock .connect (addr )
202
190
reader , writer = await asyncio .open_unix_connection (
@@ -209,12 +197,12 @@ async def client_2(addr):
209
197
writer .write (b'BBBB' )
210
198
self .assertEqual (await reader .readexactly (4 ), b'SPAM' )
211
199
212
- nonlocal CNT
213
- CNT += 1
214
-
215
200
writer .close ()
216
201
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 ):
218
206
sock = socket .socket (socket .AF_UNIX )
219
207
sock .connect (addr )
220
208
reader , writer = await asyncio .open_connection (
@@ -227,11 +215,28 @@ async def client_3(addr):
227
215
writer .write (b'BBBB' )
228
216
self .assertEqual (await reader .readexactly (4 ), b'SPAM' )
229
217
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 )
230
237
nonlocal CNT
231
238
CNT += 1
232
239
233
- writer .close ()
234
-
235
240
def run (coro ):
236
241
nonlocal CNT
237
242
CNT = 0
@@ -252,9 +257,7 @@ def run(coro):
252
257
253
258
self .assertEqual (CNT , TOTAL_CNT )
254
259
255
- run (client )
256
- run (client_2 )
257
- run (client_3 )
260
+ run (client_wrapper )
258
261
259
262
def test_create_unix_connection_2 (self ):
260
263
with tempfile .NamedTemporaryFile () as tmp :
0 commit comments