Skip to content

Commit

Permalink
test(event-loop): loosen setTimeout(..., 0) timeout to 0.05s becaus…
Browse files Browse the repository at this point in the history
…e it won't be precisely 0s
  • Loading branch information
Xmader committed Feb 16, 2024
1 parent 5a25afd commit 4ac7aab
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions tests/python/test_event_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ def to_raise(msg):
assert 3.0 == await pm.eval("new Promise((resolve) => setTimeout(function(){ resolve(arguments.length) }, 100, 90, 91, 92))")
assert 92.0 == await pm.eval("new Promise((resolve) => setTimeout((...args) => { resolve(args[2]) }, 100, 90, 91, 92))")
# test `setTimeout` setting delay to 0 if < 0
await asyncio.wait_for(pm.eval("new Promise((resolve) => setTimeout(resolve, 0))"), timeout=0.02)
await asyncio.wait_for(pm.eval("new Promise((resolve) => setTimeout(resolve, -10000))"), timeout=0.02) # won't be precisely 0s
await asyncio.wait_for(pm.eval("new Promise((resolve) => setTimeout(resolve, 0))"), timeout=0.05)
await asyncio.wait_for(pm.eval("new Promise((resolve) => setTimeout(resolve, -10000))"), timeout=0.05) # won't be precisely 0s
# test `setTimeout` accepting string as the delay, coercing to a number.
# Number('100') -> 100, pass if the actual delay is > 90ms and < 120ms
await asyncio.wait_for(pm.eval("new Promise((resolve) => setTimeout(resolve, '100'))"), timeout=0.12) # won't be precisely 100ms
# Number('100') -> 100, pass if the actual delay is > 90ms and < 150ms
await asyncio.wait_for(pm.eval("new Promise((resolve) => setTimeout(resolve, '100'))"), timeout=0.15) # won't be precisely 100ms
with pytest.raises(asyncio.exceptions.TimeoutError):
await asyncio.wait_for(pm.eval("new Promise((resolve) => setTimeout(resolve, '100'))"), timeout=0.09)
# Number("1 second") -> NaN -> delay turns to be 0s
await asyncio.wait_for(pm.eval("new Promise((resolve) => setTimeout(resolve, '1 second'))"), timeout=0.02) # won't be precisely 0s
await asyncio.wait_for(pm.eval("new Promise((resolve) => setTimeout(resolve, '1 second'))"), timeout=0.05) # won't be precisely 0s

# passing an invalid ID to `clearTimeout` should silently do nothing; no exception is thrown.
pm.eval("clearTimeout(NaN)")
Expand Down

0 comments on commit 4ac7aab

Please sign in to comment.