Skip to content

Commit

Permalink
Improved testing suite
Browse files Browse the repository at this point in the history
  • Loading branch information
mattwarkentin committed Jan 8, 2025
1 parent 9e1ad4b commit a10b699
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
25 changes: 21 additions & 4 deletions tests/testthat/helper-oms.R
Original file line number Diff line number Diff line change
@@ -1,11 +1,28 @@
local_initiate_oms <- function(path) {
cmd <- if (Sys.info()['sysname'] == 'Windows') './bin/oms.exe' else './bin/oms'
local_initiate_oms <- function(path, env = rlang::caller_env()) {
cmd <- if (Sys.info()['sysname'] == 'Windows') '.\\bin\\oms.exe' else 'bin/oms'
pid <-
withr::with_dir(
new = path,
code = sys::exec_background(cmd = cmd, std_out = FALSE)
)
Sys.sleep(0.5)
withr::defer_parent(tools::pskill(pid))
withr::defer(tools::pskill(pid), envir = env)
ensure_oms_running(pid)
allow_startup()
pid
}

check_oms_running <- function(pid) {
status <- sys::exec_status(pid, wait = FALSE)
if (rlang::is_na(status)) return(TRUE)
rlang::abort('OpenM++ Web Service (OMS) is not running.')
}

ensure_oms_running <-
purrr::insistently(
f = \(x) check_oms_running(x),
rate = purrr::rate_delay(pause = 0.1, max_times = 10)
)

allow_startup <- function(time = 1L) {
Sys.sleep(time)
}
8 changes: 6 additions & 2 deletions tests/testthat/setup.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ local_install_openmpp <- function() {

if (os == 'Darwin' & type == 'arm64') {
url <- 'https://github.com/openmpp/main/releases/latest/download/openmpp_mac_arm64_20241226.tar.gz'
} else if (os == 'Darwin' & type == 'intel') {
} else if (os == 'Darwin' & type == 'x86_64') {
url <- 'https://github.com/openmpp/main/releases/latest/download/openmpp_mac_x86_64_20241226.tar.gz'
} else if (os == 'Linux') {
url <- 'https://github.com/openmpp/main/releases/latest/download/openmpp_debian-11_20241226.tar.gz'
Expand All @@ -14,9 +14,14 @@ local_install_openmpp <- function() {
} else {
rlang::abort('No compatible OS detected.')
}

file <- basename(url)

dir <- tempdir()

path <- paste0(dir, '/', file)
withr::defer(unlink(path))

download.file(url, path, quiet = TRUE)

if (os == 'Windows') {
Expand All @@ -25,7 +30,6 @@ local_install_openmpp <- function() {
untar(path, exdir = dir)
}

unlink(path)
new_path <- tools::file_path_sans_ext(path, compression = TRUE)
new_path
}
Expand Down

0 comments on commit a10b699

Please sign in to comment.