Skip to content

Commit 30f3f0c

Browse files
committed
test(event-loop): testing .unref() on setInterval timers
1 parent 61fb3ec commit 30f3f0c

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

tests/python/test_event_loop.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import pythonmonkey as pm
33
import asyncio
44

5-
def test_timers_unref():
5+
def test_setTimeout_unref():
66
async def async_fn():
77
obj = {'val': 0}
88
pm.eval("""(obj) => {
@@ -17,6 +17,18 @@ async def async_fn():
1717
return True
1818
assert asyncio.run(async_fn())
1919

20+
def test_setInterval_unref():
21+
async def async_fn():
22+
obj = {'val': 0}
23+
pm.eval("""(obj) => {
24+
setInterval(()=>{ obj.val++ }, 200).unref()
25+
setTimeout(()=>{ }, 500)
26+
}""")(obj)
27+
await pm.wait() # It should stop after the setTimeout timer's 500ms.
28+
assert obj['val'] == 2 # The setInterval timer should only run twice (500 // 200 == 2)
29+
return True
30+
assert asyncio.run(async_fn())
31+
2032
def test_finished_timer_ref():
2133
async def async_fn():
2234
# Making sure the event-loop won't be activated again when a finished timer gets re-refed.

0 commit comments

Comments
 (0)