|
| 1 | +#' @tags interrupt lazy |
| 2 | +#' @tags detritus-files |
| 3 | +#' @tags multisession multicore |
| 4 | + |
| 5 | +library(future) |
| 6 | +options(future.debug = FALSE) |
| 7 | + |
| 8 | +strategies <- supportedStrategies() |
| 9 | +strategies <- setdiff(strategies, "sequential") |
| 10 | + |
| 11 | +## IMPORTANT: Skip when testing with 'covr', because value() cancels the |
| 12 | +## still-running futures when one of them fails, which terminates their |
| 13 | +## workers. See 'test-value-error-cancels-set.R' for details |
| 14 | +if (covr_testing) { |
| 15 | + message("Skipping, because covr is used for testing") |
| 16 | + strategies <- character(0L) |
| 17 | +} |
| 18 | + |
| 19 | +for (strategy in strategies) { |
| 20 | + message(sprintf("plan('%s') ...", strategy)) |
| 21 | + plan(strategy) |
| 22 | + |
| 23 | + n0 <- nbrOfFreeWorkers() |
| 24 | + |
| 25 | + for (inorder in c(TRUE, FALSE)) { |
| 26 | + message(sprintf("inorder = %s ...", inorder)) |
| 27 | + |
| 28 | + ## A lazy future that fails to launch, because it is claimed to be |
| 29 | + ## owned by another R session |
| 30 | + f1 <- future(1, lazy = TRUE) |
| 31 | + f1[["owner"]] <- structure("not-my-session", source = list(pid = 1L, host = "nowhere")) |
| 32 | + |
| 33 | + ## A running future |
| 34 | + f2 <- future({ Sys.sleep(5); 99 }) |
| 35 | + |
| 36 | + res <- tryCatch(value(list(f1, f2), inorder = inorder), error = identity) |
| 37 | + |
| 38 | + message("Assert the launch error is signaled") |
| 39 | + stopifnot(inherits(res, "error")) |
| 40 | + |
| 41 | + message("Assert the running future was canceled and resolved") |
| 42 | + stopifnot(resolved(f2)) |
| 43 | + res2 <- tryCatch(value(f2), error = identity) |
| 44 | + stopifnot(inherits(res2, "FutureCanceledError")) |
| 45 | + |
| 46 | + message("Assert all workers are released") |
| 47 | + stopifnot(nbrOfFreeWorkers() == n0) |
| 48 | + |
| 49 | + message(sprintf("inorder = %s ... done", inorder)) |
| 50 | + } |
| 51 | + |
| 52 | + message(sprintf("plan('%s') ... done", strategy)) |
| 53 | +} |
| 54 | + |
| 55 | +message("Shut down future backend") |
| 56 | +plan(sequential) |
| 57 | +gc() |
0 commit comments