@@ -317,12 +317,43 @@ def test_future_exception_never_retrieved(self):
317
317
def test_future_exception_never_retrieved_debug (self ):
318
318
self .check_future_exception_never_retrieved (True )
319
319
320
- def test_future_set_result_unless_cancelled (self ):
321
- from asyncio import futures
322
- fut = self .create_future ()
323
- fut .cancel ()
324
- futures ._set_result_unless_cancelled (fut , 2 )
325
- self .assertTrue (fut .cancelled ())
320
+ def test_future_wrap_future (self ):
321
+ from uvloop .loop import _wrap_future
322
+ def run (arg ):
323
+ return (arg , threading .get_ident ())
324
+ ex = concurrent .futures .ThreadPoolExecutor (1 )
325
+ f1 = ex .submit (run , 'oi' )
326
+ f2 = _wrap_future (f1 , loop = self .loop )
327
+ res , ident = self .loop .run_until_complete (f2 )
328
+ self .assertIsInstance (f2 , asyncio .Future )
329
+ self .assertEqual (res , 'oi' )
330
+ self .assertNotEqual (ident , threading .get_ident ())
331
+
332
+ def test_future_wrap_future_future (self ):
333
+ from uvloop .loop import _wrap_future
334
+ f1 = self .create_future ()
335
+ f2 = _wrap_future (f1 )
336
+ self .assertIs (f1 , f2 )
337
+
338
+ def test_future_wrap_future_cancel (self ):
339
+ from uvloop .loop import _wrap_future
340
+ f1 = concurrent .futures .Future ()
341
+ f2 = _wrap_future (f1 , loop = self .loop )
342
+ f2 .cancel ()
343
+ test_utils .run_briefly (self .loop )
344
+ self .assertTrue (f1 .cancelled ())
345
+ self .assertTrue (f2 .cancelled ())
346
+
347
+ def test_future_wrap_future_cancel2 (self ):
348
+ from uvloop .loop import _wrap_future
349
+ f1 = concurrent .futures .Future ()
350
+ f2 = _wrap_future (f1 , loop = self .loop )
351
+ f1 .set_result (42 )
352
+ f2 .cancel ()
353
+ test_utils .run_briefly (self .loop )
354
+ self .assertFalse (f1 .cancelled ())
355
+ self .assertEqual (f1 .result (), 42 )
356
+ self .assertTrue (f2 .cancelled ())
326
357
327
358
328
359
class _TestFuturesDoneCallbacks :
0 commit comments