Skip to content

Commit

Permalink
TESTS: Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
HenrikBengtsson committed Feb 11, 2025
1 parent c2f2d42 commit 3accc5a
Show file tree
Hide file tree
Showing 29 changed files with 68 additions and 168 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: future
Version: 1.34.0-9120
Version: 1.34.0-9121
Title: Unified Parallel and Distributed Processing in R for Everyone
Imports:
digest,
Expand Down
3 changes: 0 additions & 3 deletions tests/ClusterRegistry.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ message("*** ClusterRegistry() ... ")

allCores <- 1:availCores

## Speed up CRAN checks: Skip on CRAN Windows 32-bit
if (isWin32) allCores <- NULL

for (cores in allCores) {
message(sprintf("Testing with %d cores ...", cores))
options(mc.cores = cores)
Expand Down
61 changes: 29 additions & 32 deletions tests/cluster,worker-termination.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,12 @@ Sys.setenv(TMPDIR = tempdir())

message("*** cluster() - terminating worker ...")

message("Library paths: ", paste(sQuote(.libPaths()), collapse = ", "))
message("Library paths: ", commaq(.libPaths()))
message("Package path: ", sQuote(system.file(package = "future")))
message("TMPDIR for parallel workers: ", sQuote(Sys.getenv("TMPDIR")))

types <- "PSOCK"

## Speed up CRAN checks: Skip on CRAN Windows 32-bit
if (isWin32) types <- NULL

if (supportsMulticore()) types <- c(types, "FORK")

pid <- Sys.getpid()
Expand All @@ -32,36 +29,36 @@ for (type in types) {

## Crashing FORK:ed processes seems too harsh on R (< 3.3.0)
if (type != "FORK" || getRversion() >= "3.3.0") {
message("*** cluster() - crashed worker ...")

plan(cluster, workers = cl, .skip = FALSE)
x %<-% 42L
stopifnot(x == 42L)
message("*** cluster() - crashed worker ...")

plan(cluster, workers = cl, .skip = FALSE)
x %<-% 42L
stopifnot(x == 42L)

## Force R worker to terminate
## It's not safe to use quit() here when using type = "FORK" [1]
## [1] https://stat.ethz.ch/pipermail/r-devel/2021-August/080995.html
x %<-% tools::pskill(pid = Sys.getpid())
res <- tryCatch(y <- x, error = identity)
print(res)
stopifnot(
inherits(res, "error"),
inherits(res, "FutureError")
)

## Force R worker to terminate
## It's not safe to use quit() here when using type = "FORK" [1]
## [1] https://stat.ethz.ch/pipermail/r-devel/2021-August/080995.html
x %<-% tools::pskill(pid = Sys.getpid())
res <- tryCatch(y <- x, error = identity)
print(res)
stopifnot(
inherits(res, "error"),
inherits(res, "FutureError")
)

## Cleanup
print(cl)
## FIXME: Why doesn't this work here? It causes the below future to stall.
# parallel::stopCluster(cl)

## Verify that the reset worked
cl <- parallel::makeCluster(1L, type = type, timeout = 60)
print(cl)
plan(cluster, workers = cl, .skip = FALSE)
x %<-% 43L
stopifnot(x == 43L)
## Cleanup
print(cl)
## FIXME: Why doesn't this work here? It causes the below future to stall.
# parallel::stopCluster(cl)

message("*** cluster() - crashed worker ... DONE")
## Verify that the reset worked
cl <- parallel::makeCluster(1L, type = type, timeout = 60)
print(cl)
plan(cluster, workers = cl, .skip = FALSE)
x %<-% 43L
stopifnot(x == 43L)

message("*** cluster() - crashed worker ... DONE")
} ## if (type != "FORK" || getRversion() >= "3.3.0")

## Sanity checks
Expand Down
7 changes: 2 additions & 5 deletions tests/cluster-missing-future-pkg.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,12 @@ options(future.debug = FALSE)

message("*** cluster() ...")

message("Library paths: ", paste(sQuote(.libPaths()), collapse = ", "))
message("Library paths: ", commaq(.libPaths()))
message("Package path: ", sQuote(system.file(package = "future")))

types <- "PSOCK"

## Speed up CRAN checks: Skip on CRAN Windows 32-bit
if (isWin32) types <- NULL

if (supportsMulticore() && !on_solaris) types <- c(types, "FORK")
if (supportsMulticore()) types <- c(types, "FORK")

setupClusterWithoutPkgs <- function(type = "PSOCK", withouts = c("future")) {
message("setupClusterWithoutPkgs() ...")
Expand Down
15 changes: 5 additions & 10 deletions tests/cluster.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@ source("incl/start.R")
options(future.debug = FALSE)
message("*** cluster() ...")

message("Library paths: ", paste(sQuote(.libPaths()), collapse = ", "))
message("Library paths: ", commaq(.libPaths()))
message("Package path: ", sQuote(system.file(package = "future")))

types <- "PSOCK"

## Speed up CRAN checks: Skip on CRAN Windows 32-bit
if (isWin32) types <- NULL

if (supportsMulticore() && !on_solaris) types <- c(types, "FORK")
if (supportsMulticore()) types <- c(types, "FORK")

## WORKAROUND: covr::package_coverage() -> merge_coverage() -> ... produces
## "Error in readRDS(x) : error reading from connection" for type = "FORK".
Expand Down Expand Up @@ -49,7 +46,7 @@ for (type in types) {
v <- grep("^[.][.][.]future[.]", v, invert = TRUE, value = TRUE)
if (length(v) > 0) {
stop(sprintf("Stray variables in the global environment of %s: %s",
class(f)[1], paste(sQuote(v), collapse = ", ")))
class(f)[1], commaq(v)))
}

## No global variables
Expand Down Expand Up @@ -116,7 +113,7 @@ for (type in types) {
print(f)
v <- value(f, signal = FALSE)
print(v)
stopifnot(inherits(v, "simpleError"))
stopifnot(inherits(v, "error"))

res <- tryCatch(value(f), error = identity)
print(res)
Expand Down Expand Up @@ -171,7 +168,7 @@ for (type in types) {
v <- grep("^[.][.][.]future[.]", v, invert = TRUE, value = TRUE)
if (length(v) > 0) {
stop(sprintf("Stray variables in the global environment of %s: %s",
class(f)[1], paste(sQuote(v), collapse = ", ")))
class(f)[1], commaq(v)))
}

## Sanity checks
Expand Down Expand Up @@ -238,8 +235,6 @@ for (type in types) {

library("parallel")
for (type in types) {
if (on_solaris) next

message(sprintf("Test set #2 with cluster type %s ...", sQuote(type)))

message("*** cluster() - setDefaultCluster() ...")
Expand Down
2 changes: 1 addition & 1 deletion tests/demo.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ message("*** Fibonacci demo of the 'future' package ... DONE")


message("*** Mandelbrot demo of the 'future' package ...")
if (getRversion() >= "3.2.0" && !isWin32) {
if (getRversion() >= "3.2.0") {
options(future.demo.mandelbrot.nrow = 2L)
options(future.demo.mandelbrot.resolution = 50L)
options(future.demo.mandelbrot.delay = FALSE)
Expand Down
3 changes: 0 additions & 3 deletions tests/dotdotdot.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ source("incl/start.R")
library("listenv")

for (cores in 1:availCores) {
## Speed up CRAN checks: Skip on CRAN Windows 32-bit
if (!fullTest && isWin32) next

message(sprintf("Testing with %d cores ...", cores))
options(mc.cores = cores)

Expand Down
3 changes: 0 additions & 3 deletions tests/future,labels.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ message("*** Futures - labels ...")

strategies <- supportedStrategies()

## Speed up CRAN checks: Skip on CRAN Windows 32-bit
if (!fullTest && isWin32) strategies <- NULL

for (strategy in strategies) {
message(sprintf("- plan('%s') ...", strategy))
plan(strategy)
Expand Down
3 changes: 0 additions & 3 deletions tests/future,optsenvvars.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ message("*** Futures - undo R options and environment variables ...")

strategies <- supportedStrategies()

## Speed up CRAN checks: Skip on CRAN Windows 32-bit
if (!fullTest && isWin32) strategies <- NULL

options(digits = 6L)
Sys.setenv(R_DEFAULT_INTERNET_TIMEOUT = "300")
old_options <- options()
Expand Down
3 changes: 0 additions & 3 deletions tests/futureAssign.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ message("*** futureAssign() - sequential w/ lazy evaluation ... DONE")
message("*** futureAssign() - lazy = TRUE / FALSE ...")

for (cores in 1:availCores) {
## Speed up CRAN checks: Skip on CRAN Windows 32-bit
if (!fullTest && isWin32) next

message(sprintf("Testing with %d cores ...", cores))
options(mc.cores = cores)

Expand Down
3 changes: 0 additions & 3 deletions tests/futureAssign_OP.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ source("incl/start.R")
message("*** %<-% ...")

for (cores in 1:availCores) {
## Speed up CRAN checks: Skip on CRAN Windows 32-bit
if (!fullTest && isWin32) next

message(sprintf("Testing with %d cores ...", cores))
options(mc.cores = cores)

Expand Down
3 changes: 0 additions & 3 deletions tests/futureCall.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ args <- list(x = 42, y = 12)
v0 <- do.call(function(x, y) a * (x - y), args = args)

for (cores in 1:availCores) {
## Speed up CRAN checks: Skip on CRAN Windows 32-bit
if (!fullTest && isWin32) next

message(sprintf("Testing with %d cores ...", cores))
options(mc.cores = cores)
strategies <- supportedStrategies(cores)
Expand Down
3 changes: 0 additions & 3 deletions tests/globals,NSE.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ data <- data.frame(x = 1:5, y = 1:5)
v0 <- subset(data, x < 3)$y

for (strategy in supportedStrategies()) {
## Speed up CRAN checks: Skip on CRAN Windows 32-bit
if (!fullTest && isWin32) next

message(sprintf("- Strategy: %s ...", strategy))

plan(strategy)
Expand Down
17 changes: 2 additions & 15 deletions tests/globals,S4methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,12 @@ for (strategy in supportedStrategies()) {
rm(list = "my_fcn")
v <- tryCatch(value(f), error = identity)
print(v)
if (isTRUE(as.logical(Sys.getenv("R_CHECK_IDEAL")))) {
message("R_CHECK_IDEAL=TRUE")
if (getOption("future.globals.keepWhere", TRUE)) {
message("future.globals.keepWhere=TRUE")
stopifnot(identical(v, truth))
} else {
message("future.globals.keepWhere=FALSE")
stopifnot(inherits(v, "error"))
}
} else if (isTRUE(getOption("future.globals.keepWhere", FALSE))) {
if (isTRUE(getOption("future.globals.keepWhere", FALSE))) {
message("future.globals.keepWhere=TRUE")
stopifnot(identical(v, truth))
} else {
message("future.globals.keepWhere=FALSE")
if (strategy %in% c("sequential", "multicore")) {
stopifnot(inherits(v, "error"))
} else {
stopifnot(inherits(v, "error"))
}
stopifnot(inherits(v, "error"))
}
my_fcn <- org_my_fcn
}
Expand Down
3 changes: 0 additions & 3 deletions tests/globals,formulas.R
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,6 @@ str(y_iv)


for (cores in 1:availCores) {
## Speed up CRAN checks: Skip on CRAN Windows 32-bit
if (!fullTest && isWin32) next

message(sprintf("Testing with %d cores ...", cores))
options(mc.cores = cores)

Expand Down
29 changes: 2 additions & 27 deletions tests/globals,locals.R
Original file line number Diff line number Diff line change
Expand Up @@ -79,26 +79,7 @@ for (strategy in supportedStrategies()) {

res <- tryCatch({ v <- value(f) }, error = identity)
print(res)

if (isTRUE(as.logical(Sys.getenv("R_CHECK_IDEAL")))) {
stopifnot(identical(v, truth))
} else if (isTRUE(getOption("future.globals.keepWhere", FALSE))) {
message("future.globals.keepWhere=TRUE")
if (isTRUE(getOption("future.globals.globalsOf.locals", TRUE))) {
message("future.globals.globalsOf.locals=TRUE")
if (strategy %in% c("sequential", "multicore")) {
stopifnot(identical(v, truth))
} else {
stopifnot(identical(v, truth))
}
} else {
message("future.globals.globalsOf.locals=FALSE")
stopifnot(identical(v, truth))
}
} else {
message("future.globals.keepWhere=FALSE")
stopifnot(identical(v, truth))
}
stopifnot(identical(v, truth))
})


Expand Down Expand Up @@ -134,13 +115,7 @@ for (strategy in supportedStrategies()) {
stopifnot(identical(v, truth))
} else if (isTRUE(getOption("future.globals.keepWhere", FALSE))) {
message("future.globals.keepWhere=TRUE")
if (isTRUE(getOption("future.globals.globalsOf.locals", TRUE))) {
message("future.globals.globalsOf.locals=TRUE")
stopifnot(identical(v, truth))
} else {
message("future.globals.globalsOf.locals=FALSE")
stopifnot(identical(v, truth))
}
stopifnot(identical(v, truth))
} else {
message("future.globals.keepWhere=FALSE")
if (isTRUE(getOption("future.globals.globalsOf.locals", TRUE))) {
Expand Down
2 changes: 1 addition & 1 deletion tests/globals,manual.R
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ for (strategy in supportedStrategies()) {
rm(list = names(globals))
y <- tryCatch(value(f), error = identity)
if (!inherits(f, c("SequentialFuture", "UniprocessFuture", "MulticoreFuture"))) {
stopifnot(inherits(y, "simpleError"))
stopifnot(inherits(y, "error"))
}


Expand Down
3 changes: 0 additions & 3 deletions tests/globals,subassignment.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ stopifnot(identical(y, y0))
stopifnot(identical(x, list()))

for (cores in 1:availCores) {
## Speed up CRAN checks: Skip on CRAN Windows 32-bit
if (!fullTest && isWin32) next

message(sprintf("Testing with %d cores ...", cores))
options(mc.cores = cores)

Expand Down
3 changes: 0 additions & 3 deletions tests/globals,tricky.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ oopts <- c(oopts, options(
message("*** Tricky use cases related to globals ...")

for (cores in 1:availCores) {
## Speed up CRAN checks: Skip on CRAN Windows 32-bit
if (!fullTest && isWin32) next

message(sprintf("Testing with %d cores ...", cores))
options(mc.cores = cores)

Expand Down
Loading

0 comments on commit 3accc5a

Please sign in to comment.