|
| 1 | + |
| 2 | + |
| 3 | + |
| 4 | + |
| 5 | +for (strategy in c( |
| 6 | + "sequential", |
| 7 | + "transparent", |
| 8 | + "multisession", |
| 9 | + "multicore", |
| 10 | + "multiprocess", |
| 11 | + "cluster" |
| 12 | +)){ |
| 13 | + context(sprintf("future plan = '%s'", strategy)) |
| 14 | + test_that(paste0(strategy, ": Logging works"), { |
| 15 | + skip_if_not_installed("future") |
| 16 | + skip_if_not_installed("future.apply") |
| 17 | + future::plan(strategy) |
| 18 | + |
| 19 | + tf <- tempfile() |
| 20 | + |
| 21 | + lr <- Logger$new("par_root", parent = NULL, appenders = AppenderFile$new(tf)) |
| 22 | + lg <- lr$spawn("par_child") |
| 23 | + |
| 24 | + x <- future::future(lr$info("root_logger")) |
| 25 | + x <- future::value(x) |
| 26 | + expect_match(readLines(tf)[[1]], "root_logger") |
| 27 | + |
| 28 | + y <- future::future(lg$info("child_logger")) |
| 29 | + y <- future::value(y) |
| 30 | + expect_match(readLines(tf)[[2]], "child_logger") |
| 31 | + |
| 32 | + future.apply::future_lapply( |
| 33 | + c("flapply 1", "flapply 2"), |
| 34 | + function(.x) lr$info("root %s", .x, pid = Sys.getpid()) |
| 35 | + ) |
| 36 | + expect_match(readLines(tf)[[3]], "root.*flapply 1") |
| 37 | + expect_match(readLines(tf)[[4]], "root.*flapply 2") |
| 38 | + |
| 39 | + future.apply::future_lapply( |
| 40 | + c("flapply 1", "flapply 2"), |
| 41 | + function(.x) lr$info("child %s", .x) |
| 42 | + ) |
| 43 | + expect_match(readLines(tf)[[5]], "child.*flapply 1") |
| 44 | + expect_match(readLines(tf)[[6]], "child.*flapply 2") |
| 45 | + unlink(tf) |
| 46 | + }) |
| 47 | + |
| 48 | + |
| 49 | +} |
| 50 | + |
0 commit comments