1
1
# Test that coros scheduled to run at some time don't run prematurely
2
2
# in case of I/O completion before that.
3
3
import uasyncio .core as uasyncio
4
+ import logging
5
+ logging .basicConfig (level = logging .DEBUG )
6
+ #uasyncio.set_debug(True)
7
+
4
8
5
9
class MockEventLoop (uasyncio .EventLoop ):
6
10
@@ -16,15 +20,25 @@ def pass_time(self, delta):
16
20
self .t += delta
17
21
18
22
def wait (self , delay ):
23
+ #print("%d: wait(%d)" % (self.t, delay))
19
24
self .pass_time (100 )
25
+
20
26
if self .t == 100 :
21
- self .call_soon (lambda : self .msgs .append ("I should be run first, time: %s" % self .time ()))
27
+ def cb_1st ():
28
+ self .msgs .append ("I should be run first, time: %s" % self .time ())
29
+ self .call_soon (cb_1st )
30
+
22
31
if self .t == 1000 :
23
32
raise StopIteration
24
33
25
34
26
35
loop = MockEventLoop ()
27
- loop .call_later_ms (500 , lambda : loop .msgs .append ("I should be run second, time: %s" % loop .time ()))
36
+
37
+ def cb_2nd ():
38
+ loop .msgs .append ("I should be run second, time: %s" % loop .time ())
39
+
40
+ loop .call_later_ms (500 , cb_2nd )
41
+
28
42
try :
29
43
loop .run_forever ()
30
44
except StopIteration :
@@ -33,4 +47,4 @@ def wait(self, delay):
33
47
print (loop .msgs )
34
48
# .wait() is now called on each loop iteration, and for our mock case, it means that
35
49
# at the time of running, self.time() will be skewed by 100 virtual time units.
36
- assert loop .msgs == ['I should be run first, time: 200' , 'I should be run second, time: 600' ]
50
+ assert loop .msgs == ['I should be run first, time: 200' , 'I should be run second, time: 600' ], str ( loop . msgs )
0 commit comments