Commit fb065b64 authored by Kirill Smelkov's avatar Kirill Smelkov

time: test: Add test for stop on func-based Timer

I was working on Timer-related topics and started to suspect that stop
might become panicking when draining timer channel if func != nil. That
turned out to be not true - the code is correct as it is, but it
generally helps to have tests covering questionable functionality.

/proposed-for-review-on nexedi/pygolang!26
parent 9fafad8e
......@@ -199,6 +199,22 @@ def test_timer_stop_drain():
assert len(tx.c) == 0
# test_timer_stop_vs_func verifies that Timer .stop() works correctly with func-timer.
@func
def test_timer_stop_vs_func():
tv = []
def _1(): tv.append(1)
def _2(): tv.append(2)
t1 = time.after_func(1e6*dt, _1); defer(t1.stop)
t2 = time.after_func( 1*dt, _2); defer(t2.stop)
time.sleep(2*dt)
assert t1.stop() == True
assert t2.stop() == False
assert tv == [2]
# test_timer_reset_armed verifies that .reset() panics if called on armed timer.
@func
def test_timer_reset_armed():
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment