Skip to content
Snippets Groups Projects
Commit 768a0ed0 authored by Johannes Boog's avatar Johannes Boog
Browse files

Merge branch '47-add-security-routine-for-output-file-import' into 'master'

Resolve "Add security routine for output file import"

Closes #47

See merge request !32
parents 9a55506a 35aa37d5
No related branches found
No related tags found
1 merge request!32Resolve "Add security routine for output file import"
...@@ -246,13 +246,22 @@ ogs6_read_output_files <- function(ogs6_obj){ ...@@ -246,13 +246,22 @@ ogs6_read_output_files <- function(ogs6_obj){
pvd_paths <- list.files(ogs6_obj$sim_path, pvd_paths <- list.files(ogs6_obj$sim_path,
"\\.pvd$", "\\.pvd$",
full.names = TRUE) full.names = TRUE)
# Wait for eventual file writing processes to finish
ogs6_obj$pvds <- lapply(pvd_paths, function(x){OGS6_pvd$new(pvd_path = x)}) t0 <- Sys.time()
while(((length(pvd_paths) == 0) | any(file.size(pvd_paths) <= 64)) &
difftime(Sys.time(), t0, units = "secs") < 2) {
Sys.sleep(0.01)
}
if (((length(pvd_paths) == 0) | any(file.size(pvd_paths) <= 64))) {
stop("Output file not written out correctly.
Unable to import *.pvd")
} else {
ogs6_obj$pvds <- lapply(pvd_paths, function(x){OGS6_pvd$new(pvd_path = x)})
}
return(invisible()) return(invisible())
} }
#===== Test benchmarks ===== #===== Test benchmarks =====
......
...@@ -81,6 +81,31 @@ test_that("ogs6_export_sim_files works", { ...@@ -81,6 +81,31 @@ test_that("ogs6_export_sim_files works", {
unlink(test_path, recursive = TRUE) unlink(test_path, recursive = TRUE)
}) })
test_that("Nonexistent *.pvd file yields an appropriate error", {
sim_path <- paste0(tmp_dir, "/run_simulation_test")
dir.create(sim_path)
# create empty ogs6 object
ogs6_obj <- OGS6$new(sim_name = "sim", sim_path = sim_path)
expect_error(ogs6_read_output_files(ogs6_obj))
unlink(sim_path, recursive = TRUE)
})
test_that("Small *.pvd file yields an appropriate error", {
sim_path <- paste0(tmp_dir, "/run_simulation_test")
dir.create(sim_path)
d <- NULL
save(d, file = paste0(sim_path, "/null.pvd"))
# create empty ogs6 object
ogs6_obj <- OGS6$new(sim_name = "sim", sim_path = sim_path)
expect_error(ogs6_read_output_files(ogs6_obj))
unlink(sim_path, recursive = TRUE)
})
#===== Test benchmarks ===== #===== Test benchmarks =====
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment