Skip to content

Commit 5b686ec

Browse files
committed
Fix #3457: Give timeout tests some slack
1 parent 8f6a97e commit 5b686ec

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

js-envs-test-kit/src/main/scala/org/scalajs/jsenv/test/TimeoutComTests.scala

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,16 @@ private[test] class TimeoutComTests(config: JSEnvSuiteConfig) {
1717
assumeTrue("JSEnv needs com support", config.supportsCom)
1818
}
1919

20+
/** Slack for timeout tests (see #3457)
21+
*
22+
* Empirically we can observe that timing can be off by ~0.1ms. By cutting
23+
* 10ms slack, we definitely account for this without compromising the tests.
24+
*/
25+
private val slack = 10.millis
26+
2027
@Test
2128
def delayedInitTest: Unit = {
22-
val deadline = 100.millis.fromNow
29+
val deadline = (100.millis - slack).fromNow
2330
val run = kit.start(s"""
2431
setTimeout(function() {
2532
scalajsCom.init(function(msg) {
@@ -47,7 +54,7 @@ private[test] class TimeoutComTests(config: JSEnvSuiteConfig) {
4754

4855
try {
4956
for (i <- 1 to 10) {
50-
val deadline = 200.millis.fromNow
57+
val deadline = (200.millis - slack).fromNow
5158
run.run.send(s"Hello World: $i")
5259
assertEquals(s"Got: Hello World: $i", run.waitNextMessage())
5360
assertTrue("Execution took too little time", deadline.isOverdue())
@@ -59,7 +66,7 @@ private[test] class TimeoutComTests(config: JSEnvSuiteConfig) {
5966

6067
@Test
6168
def intervalSendTest: Unit = {
62-
val deadline = 250.millis.fromNow
69+
val deadline = (250.millis - slack).fromNow
6370

6471
val run = kit.start(s"""
6572
scalajsCom.init(function(msg) {});

js-envs-test-kit/src/main/scala/org/scalajs/jsenv/test/TimeoutRunTests.scala

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,17 @@ private[test] class TimeoutRunTests(config: JSEnvSuiteConfig, withCom: Boolean)
1717
assumeTrue("JSEnv needs timeout support", config.supportsTimeout)
1818
}
1919

20+
/** Slack for timeout tests (see #3457)
21+
*
22+
* Empirically we can observe that timing can be off by ~0.1ms. By cutting
23+
* 10ms slack, we definitely account for this without compromising the tests.
24+
*/
25+
private val slack = 10.millis
26+
2027
@Test
2128
def basicTimeoutTest: Unit = {
2229

23-
val deadline = 300.millis.fromNow
30+
val deadline = (300.millis - slack).fromNow
2431

2532
"""
2633
setTimeout(function() { console.log("1"); }, 200);
@@ -40,7 +47,7 @@ private[test] class TimeoutRunTests(config: JSEnvSuiteConfig, withCom: Boolean)
4047

4148
@Test
4249
def intervalTest: Unit = {
43-
val deadline = 100.millis.fromNow
50+
val deadline = (100.millis - slack).fromNow
4451

4552
// We rely on the test kit to terminate the test after 5 iterations.
4653
"""

0 commit comments

Comments
 (0)