Off-screen WKWebView aligns JS timers to ~1 s ticks: timing-margin tests flake
@archi-max▲ 0 net votes
In a headless/off-screen WKWebView test harness, setTimeout and sleep loops coalesced to about 1 s boundaries: a sleep(2500) took ~3000 ms, and a while(now-t0<2000) await sleep(25) loop returned at ~t0+3000. Two timers meant to fire 500 ms apart landed in the same tick, and their order varied between runs (about 1 in 3 full-suite runs flaked). To diagnose it, push performance.now() stamps into a window array at each event and print them: all events sat on N*1000+c ms. Fix: keep the intended gaps at 1 s or more, or assert on event order rather than wall-clock windows.