Skip to content

Commit 6174909

Browse files
committed
test(parallel): add unit test to check parallel processing works (+ add mockery to renv to enable this) (#29)
1 parent 05c4717 commit 6174909

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

renv.lock

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,6 +1069,16 @@
10691069
],
10701070
"Hash": "fec5f52652d60615fdb3957b3d74324a"
10711071
},
1072+
"mockery": {
1073+
"Package": "mockery",
1074+
"Version": "0.4.4",
1075+
"Source": "Repository",
1076+
"Repository": "CRAN",
1077+
"Requirements": [
1078+
"testthat"
1079+
],
1080+
"Hash": "674d86780fecdee68504452578cb010c"
1081+
},
10721082
"munsell": {
10731083
"Package": "munsell",
10741084
"Version": "0.5.1",

tests/testthat/test-unittest.R

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,31 @@ test_that("warm-up filtering works as expected", {
100100
mock_result[["arrivals"]])
101101
expect_identical(short_warm_up[["resources"]], mock_result[["resources"]])
102102
})
103+
104+
105+
test_that("parallel processing runs successfully", {
106+
107+
# Mock simulation model function so it can run without other dependencies
108+
# This will allows us to execute runner, but when it calls model(), instead
109+
# of attempting to run a simulation, it will just return a list of dataframes
110+
test_model <- function(run_number, param, set_seed) {
111+
list(
112+
arrivals = data.frame(run = run_number, value = rnorm(1)),
113+
resources = data.frame(run = run_number, value = rnorm(1)),
114+
run_results = data.frame(run = run_number, success = TRUE)
115+
)
116+
}
117+
mockery::stub(runner, "simulation::model", test_model)
118+
param <- list(cores = 2, number_of_runs = 5)
119+
result <- runner(param, use_future_seeding = TRUE)
120+
121+
# Check if results contain expected structure
122+
expect_true("arrivals" %in% names(result))
123+
expect_true("resources" %in% names(result))
124+
expect_true("run_results" %in% names(result))
125+
126+
# Ensure results have 5 runs worth of data
127+
expect_equal(nrow(result$arrivals), 5)
128+
expect_equal(nrow(result$resources), 5)
129+
expect_equal(nrow(result$run_results), 5)
130+
})

0 commit comments

Comments
 (0)