Skip to content

Commit

Permalink
fix: partial matches
Browse files Browse the repository at this point in the history
  • Loading branch information
be-marc committed Apr 28, 2024
1 parent f16ed41 commit 7f1618a
Show file tree
Hide file tree
Showing 13 changed files with 104 additions and 49 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export(assert_rush_workers)
export(assert_rushs)
export(get_hostname)
export(heartbeat)
export(remove_rush_plan)
export(rsh)
export(rush_available)
export(rush_config)
Expand Down
2 changes: 1 addition & 1 deletion R/Rush.R
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ Rush = R6::R6Class("Rush",
wait_for_workers = function(n, timeout = Inf) {
assert_count(n)
assert_number(timeout)
timeout = if (is.finite(timeout)) timeout else rush_config()$start_worker_timeout
timeout = if (is.finite(timeout)) timeout else rush_config()$start_worker_timeout %??% Inf

start_time = Sys.time()
while(self$n_workers < n) {
Expand Down
13 changes: 13 additions & 0 deletions R/rush_plan.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#' If `NULL`, the `REDIS_URL` environment variable is parsed.
#' If `REDIS_URL` is not set, a default configuration is used.
#' See [redux::redis_config] for details.
#' @param start_worker_timeout (`numeric(1)`)\cr
#' The time in seconds to wait for a worker to start.
#'
#' @template param_n_workers
#' @template param_lgr_thresholds
Expand Down Expand Up @@ -55,6 +57,17 @@ rush_config = function() {
start_worker_timeout = rush_env$start_worker_timeout)
}

#' @title Remove Rush Plan
#'
#' @description
#' Removes the rush plan that was set by [rush_plan()].
#'
#' @export
remove_rush_plan = function() {
rm(list = ls(envir = rush_env), envir = rush_env)
invisible(NULL)
}

#' @title Rush Available
#'
#' @description
Expand Down
10 changes: 9 additions & 1 deletion man/Rush.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions man/remove_rush_plan.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion man/rush_plan.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 0 additions & 11 deletions tests/testthat/_snaps/Rush.md

This file was deleted.

3 changes: 1 addition & 2 deletions tests/testthat/helper.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ expect_rush_task = function(task) {
}

expect_rush_reset = function(rush, type = "kill") {
remove_rush_plan()
processes = rush$processes
rush$reset(type = type)
expect_list(rush$connector$command(c("KEYS", "*")), len = 0)
walk(processes, function(p) p$kill())
}

lg$set_threshold("debug")
13 changes: 13 additions & 0 deletions tests/testthat/setup.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
old_opts = options(
warnPartialMatchArgs = TRUE,
warnPartialMatchAttr = TRUE,
warnPartialMatchDollar = TRUE
)

# https://github.com/HenrikBengtsson/Wishlist-for-R/issues/88
old_opts = lapply(old_opts, function(x) if (is.null(x)) FALSE else x)

lg_rush = lgr::get_logger("rush")
old_threshold_rush = lg_rush$threshold
lg_rush$set_threshold(0)

2 changes: 2 additions & 0 deletions tests/testthat/teardown.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
options(old_opts)
lg_rush$set_threshold(old_threshold_rush)
35 changes: 19 additions & 16 deletions tests/testthat/test-Rush.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# start workers with processx --------------------------------------------------

test_that("constructing a rush controller works", {

skip_on_cran()

config = start_flush_redis()
rush = Rush$new(network_id = "test-rush", config = config)
Expand All @@ -12,15 +12,15 @@ test_that("constructing a rush controller works", {
})

test_that("workers are started", {

skip_on_cran()

config = start_flush_redis()
rush = Rush$new(network_id = "test-rush", config = config)
fun = function(x1, x2, ...) list(y = x1 + x2)

expect_data_table(rush$worker_info, nrows = 0)

worker_ids = rush$start_workers(fun = fun, n_workers = 2, lgr_threshold = c(rush = "debug"), wait_for_workers = TRUE)
worker_ids = rush$start_workers(fun = fun, n_workers = 2, lgr_thresholds = c(rush = "debug"), wait_for_workers = TRUE)
expect_equal(rush$n_workers, 2)

# check fields
Expand All @@ -39,7 +39,7 @@ test_that("workers are started", {
})

test_that("workers are started with a heartbeat", {

skip_on_cran()

config = start_flush_redis()
rush = Rush$new(network_id = "test-rush", config = config)
Expand All @@ -55,7 +55,7 @@ test_that("workers are started with a heartbeat", {
})

test_that("additional workers are started", {

skip_on_cran()

config = start_flush_redis()
rush = Rush$new(network_id = "test-rush", config = config)
Expand All @@ -81,7 +81,7 @@ test_that("additional workers are started", {
})

test_that("packages are available on the worker", {

skip_on_cran()

config = start_flush_redis()
rush = Rush$new(network_id = "test-rush", config = config)
Expand All @@ -99,7 +99,7 @@ test_that("packages are available on the worker", {
})

test_that("globals are available on the worker", {

skip_on_cran()

config = start_flush_redis()
rush = Rush$new(network_id = "test-rush", config = config)
Expand All @@ -119,7 +119,7 @@ test_that("globals are available on the worker", {
})

test_that("named globals are available on the worker", {

skip_on_cran()

config = start_flush_redis()
rush = Rush$new(network_id = "test-rush", config = config)
Expand All @@ -141,16 +141,16 @@ test_that("named globals are available on the worker", {
# start workers with script ----------------------------------------------------

test_that("worker can be started with script", {

skip_if(TRUE)
skip_on_cran()
#devskip_if(TRUE)
set.seed(1) # make log messages reproducible

root_logger = lgr::get_logger("root")
old_fmt = root_logger$appenders$cons$layout$fmt
root_logger$appenders$cons$layout$set_fmt("%L (%n): %m")

on.exit({
root_logger$appenders$cons$layout$set_fmt(old_fmt)
root_logger$appenders$console$layout$set_fmt(old_fmt)
})

config = start_flush_redis()
Expand Down Expand Up @@ -239,7 +239,6 @@ test_that("a local worker is killed", {
})

test_that("a remote worker is killed via the heartbeat", {

skip_on_os("windows")

config = start_flush_redis()
Expand Down Expand Up @@ -740,8 +739,7 @@ test_that("restarting a worker works", {
})

test_that("restarting a worker kills the worker", {

skip_on_windows()
skip_on_os("windows")

config = start_flush_redis()
rush = Rush$new(network_id = "test-rush", config = config)
Expand All @@ -753,6 +751,9 @@ test_that("restarting a worker kills the worker", {
expect_true(tools::pskill(pid, signal = 0))

rush$restart_workers(worker_ids = worker_id)

Sys.sleep(1)

expect_false(pid == rush$worker_info$pid)
expect_false(tools::pskill(pid, signal = 0))

Expand Down Expand Up @@ -855,8 +856,6 @@ test_that("snapshot option works", {
})

test_that("terminating workers on idle works", {


config = start_flush_redis()
rush = Rush$new(network_id = "test-rush", config = config)
fun = function(x1, x2, ...) list(y = x1 + x2)
Expand Down Expand Up @@ -982,6 +981,10 @@ test_that("seed is set correctly on two workers", {
# log --------------------------------------------------------------------------

test_that("printing logs with redis appender works", {
lg_rush = lgr::get_logger("rush")
old_threshold_rush = lg_rush$threshold
on.exit(lg_rush$set_threshold(old_threshold_rush))
lg_rush$set_threshold("info")

skip_if(TRUE) # does not work in testthat on environment

Expand Down
Loading

0 comments on commit 7f1618a

Please sign in to comment.