From 35aa37d55757978d9daeb1fae4b0c604f7977649 Mon Sep 17 00:00:00 2001
From: phit0 <philipp.schad@stud.uni-goettingen.de>
Date: Thu, 4 Nov 2021 11:27:51 +0100
Subject: [PATCH] [test] security routine for small (<=64B) *.pvd files

---
 R/sim_utils.R                   |  1 -
 tests/testthat/test-sim_utils.R | 11 +++++++++++
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/R/sim_utils.R b/R/sim_utils.R
index 9dd98f6..db7b80e 100644
--- a/R/sim_utils.R
+++ b/R/sim_utils.R
@@ -251,7 +251,6 @@ ogs6_read_output_files <- function(ogs6_obj){
     while(((length(pvd_paths) == 0) | any(file.size(pvd_paths) <= 64)) &
           difftime(Sys.time(), t0, units = "secs") < 2) {
         Sys.sleep(0.01)
-        warning("waiting for pvd file ...")
     }
     if (((length(pvd_paths) == 0) | any(file.size(pvd_paths) <= 64)))  {
         stop("Output file not written out correctly.
diff --git a/tests/testthat/test-sim_utils.R b/tests/testthat/test-sim_utils.R
index 8cfd42b..e820924 100644
--- a/tests/testthat/test-sim_utils.R
+++ b/tests/testthat/test-sim_utils.R
@@ -93,7 +93,18 @@ test_that("Nonexistent *.pvd file yields an appropriate error", {
 })
 
 
+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 =====
-- 
GitLab