Debian Codegraph @

inst/testme/test-autoStopCluster.R

raw
1 library(parallelly)
2
3 message("*** autoStopCluster() ...")
4
5 ## Test with debug = FALSE
6 cl <- makeClusterPSOCK(1L)
7 print(cl)
8 cl <- autoStopCluster(cl)
9 print(cl)
10 stopifnot(!is.null(attr(cl, "gcMe")))
11
12 ## Test that it doesn't add a second finalizer
13 cl <- autoStopCluster(cl)
14 print(cl)
15 stopifnot(!is.null(attr(cl, "gcMe")))
16
17 rm(list = "cl")
18 gc()
19
20
21 ## Test with debug = TRUE
22 ## Capture output from finalizer
23 f <- tempfile()
24 con <- file(f, open = "w")
25 sink(con, type = "message")
26 cl <- makeClusterPSOCK(1L)
27
28 opts <- options(parallelly.debug = TRUE)
29 cl <- autoStopCluster(cl, debug = TRUE)
30 rm(list = "cl")
31 gc()
32 sink(type = "message")
33 close(con)
34 output <- readLines(f, warn = FALSE)
35 unlink(f)
36 print(output)
37 options(opts)
38
39 stopifnot(any(grepl("Finalizing cluster", output)))
40
41
42 message("*** autoStopCluster() ... DONE")