-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Respect
munitTimeout
for non-Future tests (#435)
- Loading branch information
Showing
8 changed files
with
143 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package munit | ||
|
||
import scala.scalajs.js.timers._ | ||
import scala.concurrent.Promise | ||
import scala.concurrent.duration.Duration | ||
|
||
class TimeoutSuite extends BaseSuite { | ||
override def munitTimeout: Duration = Duration(3, "ms") | ||
test("setTimeout-exceeds".fail) { | ||
val promise = Promise[Unit]() | ||
setTimeout(1000) { | ||
promise.success(()) | ||
} | ||
promise.future | ||
} | ||
test("setTimeout-passes") { | ||
val promise = Promise[Unit]() | ||
setTimeout(1) { | ||
promise.success(()) | ||
} | ||
promise.future | ||
} | ||
|
||
// We can't use an infinite loop because it blocks the main thread preventing the test from completing. | ||
// test("infinite-loop".fail) { | ||
// ThrottleCpu.run() | ||
// } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package munit | ||
|
||
object ThrottleCpu { | ||
def run(): Unit = { | ||
while (true) { | ||
// Some computationally intensive calculation | ||
1.to(1000).foreach(i => fib(i)) | ||
println("Loop") | ||
} | ||
} | ||
|
||
private final def fib(n: Int): Int = { | ||
if (n < 1) 0 | ||
else if (n == 1) n | ||
else fib(n - 1) + fib(n - 2) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters