diff --git a/tests/testthat/test-Rush.R b/tests/testthat/test-Rush.R index b41222e..1476c56 100644 --- a/tests/testthat/test-Rush.R +++ b/tests/testthat/test-Rush.R @@ -142,12 +142,11 @@ test_that("named globals are available on the worker", { test_that("worker can be started with script", { 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") + old_fmt = root_logger$appenders$console$layout$fmt + root_logger$appenders$console$layout$set_fmt("%L (%n): %m") on.exit({ root_logger$appenders$console$layout$set_fmt(old_fmt) @@ -163,7 +162,7 @@ test_that("worker can be started with script", { }) test_that("a remote worker is started", { - + skip_on_cran() config = start_flush_redis() fun = function(x1, x2, ...) list(y = x1 + x2) @@ -179,7 +178,7 @@ test_that("a remote worker is started", { # stop workers ----------------------------------------------------------------- test_that("a worker is terminated", { - + skip_on_cran() config = start_flush_redis() rush = Rush$new(network_id = "test-rush", config = config) @@ -209,7 +208,7 @@ test_that("a worker is terminated", { }) test_that("a local worker is killed", { - + skip_on_cran() config = start_flush_redis() rush = Rush$new(network_id = "test-rush", config = config) @@ -239,6 +238,7 @@ test_that("a local worker is killed", { }) test_that("a remote worker is killed via the heartbeat", { + skip_on_cran() skip_on_os("windows") config = start_flush_redis() @@ -273,7 +273,7 @@ test_that("a remote worker is killed via the heartbeat", { # low level read and write ----------------------------------------------------- test_that("reading and writing a hash works with flatten", { - + skip_on_cran() config = start_flush_redis() rush = RushWorker$new(network_id = "test-rush", config = config, host = "local") @@ -300,7 +300,7 @@ test_that("reading and writing a hash works with flatten", { }) test_that("reading and writing a hash works without flatten", { - + skip_on_cran() config = start_flush_redis() rush = Rush$new(network_id = "test-rush", config = config) @@ -327,7 +327,7 @@ test_that("reading and writing a hash works without flatten", { }) test_that("reading and writing hashes works", { - + skip_on_cran() config = start_flush_redis() rush = RushWorker$new(network_id = "test-rush", config = config, host = "local") @@ -366,7 +366,7 @@ test_that("reading and writing hashes works", { }) test_that("writing hashes to specific keys works", { - + skip_on_cran() config = start_flush_redis() rush = RushWorker$new(network_id = "test-rush", config = config, host = "local") @@ -388,7 +388,7 @@ test_that("writing hashes to specific keys works", { test_that("writing list columns works", { - + skip_on_cran() config = start_flush_redis() rush = RushWorker$new(network_id = "test-rush", config = config, host = "local") @@ -419,7 +419,7 @@ test_that("writing list columns works", { # task evaluation -------------------------------------------------------------- test_that("evaluating a task works", { - + skip_on_cran() config = start_flush_redis() rush = Rush$new(network_id = "test-rush", config = config) @@ -457,7 +457,7 @@ test_that("evaluating a task works", { }) test_that("evaluating tasks works", { - + skip_on_cran() config = start_flush_redis() rush = Rush$new(network_id = "test-rush", config = config) @@ -495,7 +495,7 @@ test_that("evaluating tasks works", { }) test_that("caching results works", { - + skip_on_cran() config = start_flush_redis() rush = Rush$new(network_id = "test-rush", config = config) @@ -578,7 +578,7 @@ test_that("a segfault on a worker is detected via the heartbeat", { # fault detection -------------------------------------------------------------- test_that("a simple error is catched", { - + skip_on_cran() skip_if(TRUE) # does not work in testthat on environment config = start_flush_redis() @@ -625,7 +625,7 @@ test_that("a simple error is catched", { }) test_that("a lost task is detected", { - + skip_on_cran() skip_if(TRUE) # does not work in testthat on environment config = start_flush_redis() @@ -672,7 +672,7 @@ test_that("a lost task is detected", { }) test_that("a lost task is detected when waiting", { - + skip_on_cran() skip_if(TRUE) # does not work in testthat on environment config = start_flush_redis() @@ -718,7 +718,7 @@ test_that("a lost task is detected when waiting", { # restart workers -------------------------------------------------------------- test_that("restarting a worker works", { - + skip_on_cran() config = start_flush_redis() rush = Rush$new(network_id = "test-rush", config = config) @@ -739,6 +739,7 @@ test_that("restarting a worker works", { }) test_that("restarting a worker kills the worker", { + skip_on_cran() skip_on_os("windows") config = start_flush_redis() @@ -763,7 +764,7 @@ test_that("restarting a worker kills the worker", { # receiving results ------------------------------------------------------------ test_that("blocking on new results works", { - + skip_on_cran() skip_if(TRUE) # does not work in testthat on environment config = start_flush_redis() @@ -784,7 +785,7 @@ test_that("blocking on new results works", { }) test_that("wait for tasks works when a task gets lost", { - + skip_on_cran() config = start_flush_redis() rush = Rush$new(network_id = "test-rush", config = config) @@ -806,7 +807,7 @@ test_that("wait for tasks works when a task gets lost", { # misc-------------------------------------------------------------------------- test_that("saving lgr logs works", { - + skip_on_cran() skip_if(TRUE) # does not work in testthat on environment config = start_flush_redis() @@ -837,7 +838,7 @@ test_that("saving lgr logs works", { }) test_that("snapshot option works", { - + skip_on_cran() config = start_flush_redis() rush = Rush$new(network_id = "test-rush", config = config) @@ -856,6 +857,8 @@ test_that("snapshot option works", { }) test_that("terminating workers on idle works", { + skip_on_cran() + config = start_flush_redis() rush = Rush$new(network_id = "test-rush", config = config) fun = function(x1, x2, ...) list(y = x1 + x2) @@ -872,7 +875,7 @@ test_that("terminating workers on idle works", { }) test_that("constants works", { - + skip_on_cran() config = start_flush_redis() rush = Rush$new(network_id = "test-rush", config = config) @@ -891,7 +894,7 @@ test_that("constants works", { # rush network without controller ---------------------------------------------- test_that("network without controller works", { - + skip_on_cran() config = start_flush_redis() rush = Rush$new(network_id = "test-rush", config = config) @@ -926,7 +929,7 @@ test_that("network without controller works", { # seed ------------------------------------------------------------------------- test_that("seeds are generated from regular rng seed", { - + skip_on_cran() config = start_flush_redis() rush = Rush$new(network_id = "test-rush", config = config, seed = 123) @@ -941,7 +944,7 @@ test_that("seeds are generated from regular rng seed", { }) test_that("seed are generated from L'Ecuyer-CMRG seed", { - + skip_on_cran() config = start_flush_redis() rush = Rush$new(network_id = "test-rush", config = config, seed = c(10407L, 1801422725L, -2057975723L, 1156894209L, 1595475487L, 210384600L, -1655729657L)) @@ -956,7 +959,7 @@ test_that("seed are generated from L'Ecuyer-CMRG seed", { }) test_that("seed is set correctly on two workers", { - + skip_on_cran() config = start_flush_redis() rush = Rush$new(network_id = "test-rush", config = config, seed = 123) @@ -981,13 +984,14 @@ test_that("seed is set correctly on two workers", { # log -------------------------------------------------------------------------- test_that("printing logs with redis appender works", { + skip_on_cran() + skip_if(TRUE) # does not work in testthat on environment + 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 - config = start_flush_redis() rush = Rush$new(network_id = "test-rush", config = config, seed = 123) fun = function(x1, x2, ...) { @@ -1025,7 +1029,7 @@ test_that("redis info works", { # large objects ---------------------------------------------------------------- test_that("evaluating a task works", { - + skip_on_cran() skip_if(TRUE) # takes too long config = start_flush_redis() diff --git a/tests/testthat/test-RushWorker.R b/tests/testthat/test-RushWorker.R index 128eaa7..21543af 100644 --- a/tests/testthat/test-RushWorker.R +++ b/tests/testthat/test-RushWorker.R @@ -1,5 +1,5 @@ test_that("constructing a rush worker works", { - + skip_on_cran() config = start_flush_redis() rush = RushWorker$new(network_id = "test-rush", config = config, host = "local") @@ -22,7 +22,7 @@ test_that("constructing a rush worker works", { }) test_that("active bindings work after construction", { - + skip_on_cran() config = start_flush_redis() rush = RushWorker$new(network_id = "test-rush", config = config, host = "local") @@ -46,7 +46,7 @@ test_that("active bindings work after construction", { }) test_that("a worker is registered", { - + skip_on_cran() config = start_flush_redis() rush = RushWorker$new(network_id = "test-rush", config = config, host = "local") @@ -66,7 +66,7 @@ test_that("a worker is registered", { }) test_that("a worker is terminated", { - + skip_on_cran() config = start_flush_redis() rush = RushWorker$new(network_id = "test-rush", config = config, host = "local") @@ -80,7 +80,7 @@ test_that("a worker is terminated", { }) test_that("a heartbeat is started", { - + skip_on_cran() config = start_flush_redis() rush = RushWorker$new(network_id = "test-rush", config = config, host = "local", heartbeat_period = 3) @@ -93,7 +93,7 @@ test_that("a heartbeat is started", { }) test_that("pushing a task to the queue works", { - + skip_on_cran() config = start_flush_redis() rush = RushWorker$new(network_id = "test-rush", config = config, host = "local") @@ -132,7 +132,7 @@ test_that("pushing a task to the queue works", { }) test_that("pushing a task with extras to the queue works", { - + skip_on_cran() config = start_flush_redis() rush = RushWorker$new(network_id = "test-rush", config = config, host = "local") @@ -174,7 +174,7 @@ test_that("pushing a task with extras to the queue works", { }) test_that("pushing tasks to the queue works", { - + skip_on_cran() config = start_flush_redis() rush = RushWorker$new(network_id = "test-rush", config = config, host = "local") @@ -214,7 +214,7 @@ test_that("pushing tasks to the queue works", { }) test_that("pushing tasks with extras to the queue works", { - + skip_on_cran() config = start_flush_redis() rush = RushWorker$new(network_id = "test-rush", config = config, host = "local") @@ -257,7 +257,7 @@ test_that("pushing tasks with extras to the queue works", { }) test_that("popping a task from the queue works", { - + skip_on_cran() config = start_flush_redis() rush = RushWorker$new(network_id = "test-rush", config = config, host = "local") @@ -299,7 +299,7 @@ test_that("popping a task from the queue works", { }) test_that("popping a task with seed, max_retries and timeout works", { - + skip_on_cran() config = start_flush_redis() rush = RushWorker$new(network_id = "test-rush", config = config, host = "local") @@ -347,7 +347,7 @@ test_that("popping a task with seed, max_retries and timeout works", { }) test_that("pushing a finished task works", { - + skip_on_cran() config = start_flush_redis() rush = RushWorker$new(network_id = "test-rush", config = config, host = "local") @@ -388,7 +388,7 @@ test_that("pushing a finished task works", { }) test_that("pushing a failed tasks works", { - + skip_on_cran() config = start_flush_redis() rush = RushWorker$new(network_id = "test-rush", config = config, host = "local") @@ -429,6 +429,8 @@ test_that("pushing a failed tasks works", { }) test_that("retry a failed task works", { + skip_on_cran() + lg_rush = lgr::get_logger("rush") old_threshold_rush = lg_rush$threshold on.exit(lg_rush$set_threshold(old_threshold_rush)) @@ -458,13 +460,13 @@ test_that("retry a failed task works", { }) test_that("retry a failed task works and setting a new seed works", { - + skip_on_cran() config = start_flush_redis() rush = RushWorker$new(network_id = "test-rush", config = config, host = "local") xss = list(list(x1 = 1, x2 = 2)) seed = c(10407L, 1280795612L, -169270483L, -442010614L, -603558397L, -222347416L, 1489374793L) - keys = rush$push_tasks(xss, seed = list(seed)) + keys = rush$push_tasks(xss, seeds = list(seed)) task = rush$pop_task(fields = c("xs", "seed")) expect_equal(task$seed, seed) @@ -529,6 +531,8 @@ test_that("retry a failed task works with a maximum of retries", { }) test_that("retry failed tasks works", { + skip_on_cran() + lg_rush = lgr::get_logger("rush") old_threshold_rush = lg_rush$threshold on.exit(lg_rush$set_threshold(old_threshold_rush)) @@ -560,7 +564,7 @@ test_that("retry failed tasks works", { }) test_that("moving and fetching tasks works", { - + skip_on_cran() config = start_flush_redis() rush = RushWorker$new(network_id = "test-rush", config = config, host = "local") @@ -635,7 +639,7 @@ test_that("moving and fetching tasks works", { }) test_that("fetching as list works", { - + skip_on_cran() config = start_flush_redis() rush = RushWorker$new(network_id = "test-rush", config = config, host = "local") @@ -691,7 +695,7 @@ test_that("fetching as list works", { }) test_that("fetch task with states works", { - + skip_on_cran() config = start_flush_redis() rush = RushWorker$new(network_id = "test-rush", config = config, host = "local", seed = 123) @@ -748,7 +752,7 @@ test_that("fetch task with states works", { }) test_that("latest results are fetched", { - + skip_on_cran() config = start_flush_redis() rush = RushWorker$new(network_id = "test-rush", config = config, host = "local") @@ -790,7 +794,7 @@ test_that("latest results are fetched", { }) test_that("priority queues work", { - + skip_on_cran() config = start_flush_redis() rush = Rush$new(network_id = "test-rush", config = config) @@ -843,7 +847,7 @@ test_that("priority queues work", { }) test_that("redirecting to shared queue works", { - + skip_on_cran() config = start_flush_redis() rush = Rush$new(network_id = "test-rush", config = config) @@ -873,7 +877,7 @@ test_that("redirecting to shared queue works", { }) test_that("mixing priority queue and shared queue works", { - + skip_on_cran() config = start_flush_redis() rush = Rush$new(network_id = "test-rush", config = config) @@ -894,6 +898,7 @@ test_that("mixing priority queue and shared queue works", { }) test_that("saving logs with redis appender works", { + skip_on_cran() appenders = lgr::get_logger("root")$appenders @@ -928,6 +933,7 @@ test_that("saving logs with redis appender works", { }) test_that("settings the buffer size in redis appender works", { + skip_on_cran() appenders = lgr::get_logger("root")$appenders @@ -959,7 +965,7 @@ test_that("settings the buffer size in redis appender works", { }) test_that("pushing tasks and terminating worker works", { - + skip_on_cran() config = start_flush_redis() rush = RushWorker$new(network_id = "test-rush", config = config, host = "local") @@ -979,7 +985,7 @@ test_that("pushing tasks and terminating worker works", { }) test_that("terminate on idle works", { - + skip_on_cran() config = start_flush_redis() rush = RushWorker$new(network_id = "test-rush", config = config, host = "local") @@ -998,7 +1004,7 @@ test_that("terminate on idle works", { # seed ------------------------------------------------------------------------- test_that("popping a task with seed from the queue works", { - + skip_on_cran() config = start_flush_redis() rush = RushWorker$new(network_id = "test-rush", config = config, host = "local", seed = 123) @@ -1015,7 +1021,7 @@ test_that("popping a task with seed from the queue works", { # atomic operations ----------------------------------------------------------- test_that("task in states works", { - + skip_on_cran() config = start_flush_redis() rush = RushWorker$new(network_id = "test-rush", config = config, host = "local", seed = 123) diff --git a/tests/testthat/test-rush_plan.R b/tests/testthat/test-rush_plan.R index 317133f..f9ac09d 100644 --- a/tests/testthat/test-rush_plan.R +++ b/tests/testthat/test-rush_plan.R @@ -1,6 +1,4 @@ test_that("rush_plan family works", { - - expect_false(rush_available()) config = redis_config() rush_plan(n_workers = 2, config) @@ -12,14 +10,12 @@ test_that("rush_plan family works", { }) test_that("rush_plan throws and error if redis is not available", { - - config = redis_config(url = "redis://localhost:1234") expect_error(rush_plan(n_workers = 2, config), "Can't connect to Redis") }) test_that("start workers", { - + skip_on_cran() config = start_flush_redis() rush_plan(n_workers = 2, config) @@ -36,6 +32,8 @@ test_that("start workers", { }) test_that("set threshold", { + skip_on_cran() + lg_rush = lgr::get_logger("rush") old_threshold_rush = lg_rush$threshold on.exit(lg_rush$set_threshold(old_threshold_rush)) @@ -55,6 +53,8 @@ test_that("set threshold", { }) test_that("set start worker timeout", { + skip_on_cran() + config = start_flush_redis() rush_plan(n_workers = 2, config, start_worker_timeout = -Inf) diff --git a/tests/testthat/test-worker_loops.R b/tests/testthat/test-worker_loops.R index 954b1cd..1a0a2e3 100644 --- a/tests/testthat/test-worker_loops.R +++ b/tests/testthat/test-worker_loops.R @@ -1,6 +1,8 @@ # default ---------------------------------------------------------------------- test_that("worker_loop_default works", { + skip_on_cran() + config = start_flush_redis() rush = RushWorker$new(network_id = "test-rush", config = config, host = "local") xss = list(list(x1 = 1, x2 = 2)) @@ -14,6 +16,8 @@ test_that("worker_loop_default works", { }) test_that("worker_loop_default works with failed task", { + skip_on_cran() + config = start_flush_redis() rush = RushWorker$new(network_id = "test-rush", config = config, host = "local") xss = list(list(x1 = 1, x2 = 2)) @@ -28,6 +32,8 @@ test_that("worker_loop_default works with failed task", { }) test_that("worker_loop_default retries failed task", { + skip_on_cran() + config = start_flush_redis() rush = RushWorker$new(network_id = "test-rush", config = config, host = "local") xss = list(list(x1 = 1, x2 = 2)) @@ -42,6 +48,8 @@ test_that("worker_loop_default retries failed task", { }) test_that("worker_loop_default sets seed is set correctly", { + skip_on_cran() + config = start_flush_redis() rush = RushWorker$new(network_id = "test-rush", config = config, host = "local", seed = 123456) xss = list(list(x1 = 1, x2 = 2), list(x1 = 2, x2 = 2), list(x1 = 3, x2 = 2)) @@ -58,6 +66,8 @@ test_that("worker_loop_default sets seed is set correctly", { # callr ------------------------------------------------------------------------ test_that("worker_loop_callr works", { + skip_on_cran() + config = start_flush_redis() rush = RushWorker$new(network_id = "test-rush", config = config, host = "local") xss = list(list(x1 = 1, x2 = 2)) @@ -71,6 +81,8 @@ test_that("worker_loop_callr works", { }) test_that("worker_loop_callr works with failed task", { + skip_on_cran() + config = start_flush_redis() rush = RushWorker$new(network_id = "test-rush", config = config, host = "local") xss = list(list(x1 = 1, x2 = 2)) @@ -85,6 +97,8 @@ test_that("worker_loop_callr works with failed task", { }) test_that("worker_loop_callr works with lost task", { + skip_on_cran() + config = start_flush_redis() rush = RushWorker$new(network_id = "test-rush", config = config, host = "local") xss = list(list(x1 = 1, x2 = 2)) @@ -99,6 +113,8 @@ test_that("worker_loop_callr works with lost task", { }) test_that("worker_loop_callr works with timeout", { + skip_on_cran() + config = start_flush_redis() rush = RushWorker$new(network_id = "test-rush", config = config, host = "local") xss = list(list(x1 = 1, x2 = 2)) @@ -113,6 +129,8 @@ test_that("worker_loop_callr works with timeout", { }) test_that("worker_loop_callr sets seed correctly", { + skip_on_cran() + config = start_flush_redis() rush = RushWorker$new(network_id = "test-rush", config = config, host = "local", seed = 123456) xss = list(list(x1 = 1, x2 = 2), list(x1 = 2, x2 = 2), list(x1 = 3, x2 = 2))