Debian Codegraph @

inst/testme/test-isLocalhostNode.R

raw
1 library(parallelly)
2
3 message("*** isLocalhostNode() ...")
4
5 ## Test isLocalhostNode.default
6 message("- isLocalhostNode.default ...")
7 res <- isLocalhostNode(list())
8 print(res)
9 stopifnot(is.na(res))
10 message("- isLocalhostNode.default ... DONE")
11
12 ## Test isLocalhostNode.RichSOCKnode
13 message("- isLocalhostNode.RichSOCKnode ...")
14 cl <- makeClusterPSOCK(1L)
15 node <- cl[[1]]
16 print(node)
17 res <- isLocalhostNode(node)
18 print(res)
19 stopifnot(isTRUE(res))
20 parallel::stopCluster(cl)
21 message("- isLocalhostNode.RichSOCKnode ... DONE")
22
23 ## Test isLocalhostNode.cluster
24 message("- isLocalhostNode.cluster ...")
25 cl <- makeClusterPSOCK(2L)
26 print(cl)
27 res <- isLocalhostNode(cl)
28 print(res)
29 stopifnot(is.logical(res), length(res) == 2L, all(res))
30 parallel::stopCluster(cl)
31 message("- isLocalhostNode.cluster ... DONE")
32
33 if (supportsMulticore()) {
34 ## Test isLocalhostNode.forknode
35 message("- isLocalhostNode.forknode ...")
36 cl <- parallel::makeForkCluster(1L)
37 node <- cl[[1]]
38 print(node)
39 res <- isLocalhostNode(node)
40 print(res)
41 stopifnot(isTRUE(res))
42 parallel::stopCluster(cl)
43 message("- isLocalhostNode.forknode ... DONE")
44 }
45
46 ## Test isLocalhostNode.SOCKnode
47 message("- isLocalhostNode.SOCKnode ...")
48 cl <- parallel::makeCluster(1L)
49 node <- cl[[1]]
50 print(node)
51 res <- isLocalhostNode(node)
52 print(res)
53 stopifnot(isTRUE(res))
54 parallel::stopCluster(cl)
55 message("- isLocalhostNode.SOCKnode ... DONE")
56
57 ## Test isLocalhostNode.RichSOCKnode with missing 'localhost' attribute
58 message("- isLocalhostNode.RichSOCKnode (no 'localhost' attr) ...")
59 cl <- makeClusterPSOCK(1L)
60 node <- cl[[1]]
61 attr(node$host, "localhost") <- NULL
62 print(node)
63 res <- isLocalhostNode(node)
64 print(res)
65 ## Should call NextMethod() which calls isLocalhostNode.SOCKnode
66 stopifnot(isTRUE(res))
67 parallel::stopCluster(cl)
68 message("- isLocalhostNode.RichSOCKnode (no 'localhost' attr) ... DONE")
69
70 message("*** isLocalhostNode() ... DONE")