Skip to content

Commit e0574a8

Browse files
committed
Get coverage of progress handler
1 parent 32109f2 commit e0574a8

File tree

3 files changed

+62
-0
lines changed

3 files changed

+62
-0
lines changed

dev-misc/fixture-creation/vegetables-dataset.R

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,26 @@ file_copy(cube_path, here("mocks", "cubes", "numa-x-mr.json"), overwrite = TRUE)
540540

541541
dir_delete(temp_dir)
542542

543+
544+
### Generate failed async crunch automation failure
545+
httpcache::clearCache()
546+
dir_create(temp_dir)
547+
548+
start_capturing(temp_dir)
549+
failed <- try(runCrunchAutomation(ds, "NOT A COMMAND", async = TRUE), silent = TRUE)
550+
stop_capturing()
551+
552+
progress_path <- path(temp_dir, "app.crunch.io/api/progress.json")
553+
554+
file_copy(
555+
progress_path,
556+
here("mocks", "app.crunch.io", "api", "progress-failed-async-script.json"),
557+
overwrite = TRUE
558+
)
559+
560+
dir_delete(temp_dir)
561+
562+
543563
# Cleanup ----
544564
rm(deck) # Hopefully gets rid of weird message after sourcing script
545565
with_consent(delete(ds))
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"element": "shoji:view",
3+
"self": "https://app.crunch.io/api/progress/",
4+
"views": {
5+
"result": "https://app.crunch.io/api/progress/result/"
6+
},
7+
"value": {
8+
"progress": -1,
9+
"message": {
10+
"resolutions": [
11+
{
12+
"column": 1,
13+
"message": "Invalid command: NOT",
14+
"command": 1,
15+
"line": 1
16+
}
17+
],
18+
"type": "script:syntax",
19+
"description": "Errors processing the script"
20+
}
21+
}
22+
}

tests/testthat/test-automation.R

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,26 @@ with_mock_crunch({
200200
)
201201
})
202202

203+
test_that("Can interpret error from async script failures", {
204+
# Override progress with a pre-generated JSON at the url
205+
with_mock(
206+
`crunch::crPOST` = function(..., progress.handler = NULL) {
207+
capture.output(crunch::pollProgress(
208+
"https://app.crunch.io/api/progress-failed-async-script.json",
209+
wait = 0.01,
210+
error_handler = progress.handler
211+
))
212+
}, {
213+
expect_error(ds <- runCrunchAutomation(ds, "NOT A COMMAND"), "Crunch Automation Error")
214+
}
215+
)
216+
217+
expect_message(
218+
failures <- showScriptErrors(),
219+
"\\(line 1\\) Invalid command: NOT",
220+
)
221+
})
222+
203223
test_that("error truncation works", {
204224
expected <- " - (line 1) Error 1\n - (line 2) Error 2\n - ... (Showing first 2 of 3 errors)"
205225
attr(expected, "truncated") <- TRUE

0 commit comments

Comments
 (0)