@@ -483,6 +483,21 @@ def foo():
483
483
484
484
self .assertEqual (res , 42 )
485
485
486
+ def test_wait_duplicate_coroutines (self ):
487
+ @asyncio .coroutine
488
+ def coro (s ):
489
+ return s
490
+ c = coro ('test' )
491
+
492
+ task = asyncio .Task (
493
+ asyncio .wait ([c , c , coro ('spam' )], loop = self .loop ),
494
+ loop = self .loop )
495
+
496
+ done , pending = self .loop .run_until_complete (task )
497
+
498
+ self .assertFalse (pending )
499
+ self .assertEqual (set (f .result () for f in done ), {'test' , 'spam' })
500
+
486
501
def test_wait_errors (self ):
487
502
self .assertRaises (
488
503
ValueError , self .loop .run_until_complete ,
@@ -757,14 +772,10 @@ def foo():
757
772
def test_as_completed_with_timeout (self ):
758
773
759
774
def gen ():
760
- when = yield
761
- self .assertAlmostEqual (0.12 , when )
762
- when = yield 0
763
- self .assertAlmostEqual (0.1 , when )
764
- when = yield 0
765
- self .assertAlmostEqual (0.15 , when )
766
- when = yield 0.1
767
- self .assertAlmostEqual (0.12 , when )
775
+ yield
776
+ yield 0
777
+ yield 0
778
+ yield 0.1
768
779
yield 0.02
769
780
770
781
loop = test_utils .TestLoop (gen )
@@ -840,6 +851,25 @@ def gen():
840
851
done , pending = loop .run_until_complete (waiter )
841
852
self .assertEqual (set (f .result () for f in done ), {'a' , 'b' })
842
853
854
+ def test_as_completed_duplicate_coroutines (self ):
855
+ @asyncio .coroutine
856
+ def coro (s ):
857
+ return s
<
8000
code>858 +
859
+ @asyncio .coroutine
860
+ def runner ():
861
+ result = []
862
+ c = coro ('ham' )
863
+ for f in asyncio .as_completed ({c , c , coro ('spam' )}, loop = self .loop ):
864
+ result .append ((yield from f ))
865
+ return result
866
+
867
+ fut = asyncio .Task (runner (), loop = self .loop )
868
+ self .loop .run_until_complete (fut )
869
+ result = fut .result ()
870
+ self .assertEqual (set (result ), {'ham' , 'spam' })
871
+ self .assertEqual (len (result ), 2 )
872
+
843
873
def test_sleep (self ):
844
874
845
875
def gen ():
@@ -1505,6 +1535,15 @@ def coro():
1505
1535
gen3 .close ()
1506
1536
gen4 .close ()
1507
1537
1538
+ def test_duplicate_coroutines (self ):
1539
+ @asyncio .coroutine
1540
+ def coro (s ):
1541
+ return s
1542
+ c = coro ('abc' )
1543
+ fut = asyncio .gather (c , c , coro ('def' ), c , loop = self .one_loop )
1544
+ self ._run_loop (self .one_loop )
1545
+ self .assertEqual (fut .result (), ['abc' , 'abc' , 'def' , 'abc' ])
1546
+
1508
1547
def test_cancellation_broadcast (self ):
1509
1548
# Cancelling outer() cancels all children.
1510
1549
proof = 0
0 commit comments