kopia lustrzana https://github.com/micropython/micropython-lib
uasyncio.core: test_full_wait.py: Make easier to debug.
rodzic
85c82e7467
commit
72a90a0c93
|
@ -1,6 +1,10 @@
|
||||||
# Test that coros scheduled to run at some time don't run prematurely
|
# Test that coros scheduled to run at some time don't run prematurely
|
||||||
# in case of I/O completion before that.
|
# in case of I/O completion before that.
|
||||||
import uasyncio.core as uasyncio
|
import uasyncio.core as uasyncio
|
||||||
|
import logging
|
||||||
|
logging.basicConfig(level=logging.DEBUG)
|
||||||
|
#uasyncio.set_debug(True)
|
||||||
|
|
||||||
|
|
||||||
class MockEventLoop(uasyncio.EventLoop):
|
class MockEventLoop(uasyncio.EventLoop):
|
||||||
|
|
||||||
|
@ -16,15 +20,25 @@ class MockEventLoop(uasyncio.EventLoop):
|
||||||
self.t += delta
|
self.t += delta
|
||||||
|
|
||||||
def wait(self, delay):
|
def wait(self, delay):
|
||||||
|
#print("%d: wait(%d)" % (self.t, delay))
|
||||||
self.pass_time(100)
|
self.pass_time(100)
|
||||||
|
|
||||||
if self.t == 100:
|
if self.t == 100:
|
||||||
self.call_soon(lambda: self.msgs.append("I should be run first, time: %s" % self.time()))
|
def cb_1st():
|
||||||
|
self.msgs.append("I should be run first, time: %s" % self.time())
|
||||||
|
self.call_soon(cb_1st)
|
||||||
|
|
||||||
if self.t == 1000:
|
if self.t == 1000:
|
||||||
raise StopIteration
|
raise StopIteration
|
||||||
|
|
||||||
|
|
||||||
loop = MockEventLoop()
|
loop = MockEventLoop()
|
||||||
loop.call_later_ms(500, lambda: loop.msgs.append("I should be run second, time: %s" % loop.time()))
|
|
||||||
|
def cb_2nd():
|
||||||
|
loop.msgs.append("I should be run second, time: %s" % loop.time())
|
||||||
|
|
||||||
|
loop.call_later_ms(500, cb_2nd)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
loop.run_forever()
|
loop.run_forever()
|
||||||
except StopIteration:
|
except StopIteration:
|
||||||
|
@ -33,4 +47,4 @@ except StopIteration:
|
||||||
print(loop.msgs)
|
print(loop.msgs)
|
||||||
# .wait() is now called on each loop iteration, and for our mock case, it means that
|
# .wait() is now called on each loop iteration, and for our mock case, it means that
|
||||||
# at the time of running, self.time() will be skewed by 100 virtual time units.
|
# at the time of running, self.time() will be skewed by 100 virtual time units.
|
||||||
assert loop.msgs == ['I should be run first, time: 200', 'I should be run second, time: 600']
|
assert loop.msgs == ['I should be run first, time: 200', 'I should be run second, time: 600'], str(loop.msgs)
|
||||||
|
|
Ładowanie…
Reference in New Issue