Commit 62244b4dc2
Verified · cmc
Tests/OrgAppTests/JavaScriptBlocksTests.swift +4 −2 · view
| @@ -255,14 +255,16 @@ struct JavaScriptBlocksTests { | ||
| 255 | 255 | @Test func cancelAndTimeoutEndTheRun() async throws { |
| 256 | 256 | let folder = FileManager.default.temporaryDirectory |
| 257 | 257 | // Spins for seconds, as an endless loop would, but ends so the test leaves no thread busy. |
| 258 | let spin = try Self.plan("#+begin_src js\nconst end = Date.now() + 3000; while (Date.now() < end) {}\n#+end_src\n") | |
| 258 | // Run to its end the two runs take 16 s of wall time whatever the load, so a limit well | |
| 259 | // under that tells stopping from finishing on a busy machine too. | |
| 260 | let spin = try Self.plan("#+begin_src js\nconst end = Date.now() + 8000; while (Date.now() < end) {}\n#+end_src\n") | |
| 259 | 261 | let start = ContinuousClock.now |
| 260 | 262 | let task = Task { try await JavaScriptBlocks.run(spin, directory: folder) } |
| 261 | 263 | try await Task.sleep(for: .milliseconds(100)) |
| 262 | 264 | task.cancel() |
| 263 | 265 | await #expect(throws: CancellationError.self) { try await task.value } |
| 264 | 266 | await #expect(throws: JavaScriptBlocks.Stopped.self) { try await JavaScriptBlocks.run(spin, directory: folder, timeout: .milliseconds(100)) } |
| 265 | #expect(ContinuousClock.now - start < .seconds(2)) | |
| 267 | #expect(ContinuousClock.now - start < .seconds(6)) | |
| 266 | 268 | let interval = try Self.plan("#+begin_src js :results output\nsetInterval(() => {}, 10)\n#+end_src\n") |
| 267 | 269 | await #expect(throws: JavaScriptBlocks.Stopped.self) { try await JavaScriptBlocks.run(interval, directory: folder, timeout: .milliseconds(100)) } |
| 268 | 270 | } |