| 1 |
library(parallelly) |
| 2 |
|
| 3 |
message("*** makeNodePSOCK() ...") |
| 4 |
|
| 5 |
makeNodePSOCK <- parallelly:::makeNodePSOCK |
| 6 |
|
| 7 |
## Test with default arguments |
| 8 |
message("- default arguments ...") |
| 9 |
## Port is required, but freePort() calls C code. |
| 10 |
## I'll use a fixed port for this test. |
| 11 |
options <- makeNodePSOCK(port = 12345L, action = "options") |
| 12 |
print(options) |
| 13 |
stopifnot(inherits(options, "makeNodePSOCKOptions")) |
| 14 |
|
| 15 |
## Test action = "options" |
| 16 |
message("- action = 'options' ...") |
| 17 |
options <- makeNodePSOCK(port = 12345L, action = "options") |
| 18 |
print(options) |
| 19 |
stopifnot(inherits(options, "makeNodePSOCKOptions")) |
| 20 |
|
| 21 |
## Test with specific worker and master |
| 22 |
message("- specific worker and master ...") |
| 23 |
options <- makeNodePSOCK(worker = "remote.server.org", master = "local.server.org", port = 12345L, action = "options") |
| 24 |
print(options) |
| 25 |
stopifnot(inherits(options, "makeNodePSOCKOptions")) |
| 26 |
|
| 27 |
## Test with rscript_sh = "cmd" |
| 28 |
message("- rscript_sh = 'cmd' ...") |
| 29 |
options <- makeNodePSOCK(port = 12345L, rscript_sh = "cmd", action = "options") |
| 30 |
print(options) |
| 31 |
stopifnot(inherits(options, "makeNodePSOCKOptions")) |
| 32 |
|
| 33 |
## Test with rscript_sh = c("sh", "cmd") |
| 34 |
if (.Platform[["OS.type"]] != "windows") { |
| 35 |
message("- rscript_sh = c('sh', 'cmd') ...") |
| 36 |
options <- makeNodePSOCK(port = 12345L, rscript_sh = c("sh", "cmd"), action = "options") |
| 37 |
print(options) |
| 38 |
stopifnot(inherits(options, "makeNodePSOCKOptions")) |
| 39 |
} |
| 40 |
|
| 41 |
## Test with rscript_args |
| 42 |
message("- rscript_args ...") |
| 43 |
options <- makeNodePSOCK(port = 12345L, rscript_args = c("--vanilla"), action = "options") |
| 44 |
print(options) |
| 45 |
stopifnot(inherits(options, "makeNodePSOCKOptions")) |
| 46 |
|
| 47 |
## Test with rscript_envs |
| 48 |
message("- rscript_envs ...") |
| 49 |
options <- makeNodePSOCK(port = 12345L, rscript_envs = c(FOO = "bar"), action = "options") |
| 50 |
print(options) |
| 51 |
stopifnot(inherits(options, "makeNodePSOCKOptions")) |
| 52 |
|
| 53 |
## Test with default_packages |
| 54 |
message("- default_packages ...") |
| 55 |
options <- makeNodePSOCK(port = 12345L, default_packages = c("stats", "*"), action = "options") |
| 56 |
print(options) |
| 57 |
stopifnot(inherits(options, "makeNodePSOCKOptions")) |
| 58 |
|
| 59 |
|
| 60 |
message("- rshcmd = '' ...") |
| 61 |
options <- makeNodePSOCK(action = "options", port = 12345L, rshcmd = "") |
| 62 |
print(options) |
| 63 |
stopifnot(inherits(options, "makeNodePSOCKOptions")) |
| 64 |
|
| 65 |
message("- rshcmd = 'ssh' ...") |
| 66 |
options <- makeNodePSOCK(action = "options", port = 12345L, rshcmd = "ssh") |
| 67 |
print(options) |
| 68 |
stopifnot(inherits(options, "makeNodePSOCKOptions")) |
| 69 |
|
| 70 |
## Test with custom 'rshcmd' function |
| 71 |
message("- rshcmd = <function> ...") |
| 72 |
options <- makeNodePSOCK(action = "options", port = 12345L, rshcmd = function(rshopts, worker) { }) |
| 73 |
print(options) |
| 74 |
stopifnot(inherits(options, "makeNodePSOCKOptions")) |
| 75 |
|
| 76 |
options <- makeNodePSOCK(action = "options", port = 12345L, rshcmd = function(rshopts, worker) { }, worker = "remote.example.org", user = "alice") |
| 77 |
print(options) |
| 78 |
stopifnot(inherits(options, "makeNodePSOCKOptions")) |
| 79 |
|
| 80 |
options <- tryCatch({ |
| 81 |
makeNodePSOCK(action = "options", port = 12345L, rshcmd = function() { }) |
| 82 |
}, error = identity) |
| 83 |
stopifnot(inherits(options, "error")) |
| 84 |
|
| 85 |
options <- tryCatch({ |
| 86 |
makeNodePSOCK(action = "options", port = 12345L, rshcmd = function(a, worker) { }) |
| 87 |
}, error = identity) |
| 88 |
stopifnot(inherits(options, "error")) |
| 89 |
|
| 90 |
options <- tryCatch({ |
| 91 |
makeNodePSOCK(action = "options", port = 12345L, rshcmd = function(rshopts, b) { }) |
| 92 |
}, error = identity) |
| 93 |
stopifnot(inherits(options, "error")) |
| 94 |
|
| 95 |
message("- rshopts = '' ...") |
| 96 |
options <- makeNodePSOCK(action = "options", port = 12345L, rshopts = "") |
| 97 |
print(options) |
| 98 |
stopifnot(inherits(options, "makeNodePSOCKOptions")) |
| 99 |
|
| 100 |
|
| 101 |
worker <- "remote.example.org" |
| 102 |
options <- makeNodePSOCK(action = "options", worker = worker, port = 12345L, rshcmd = NULL, verbose = TRUE) |
| 103 |
stopifnot(inherits(options, "makeNodePSOCKOptions")) |
| 104 |
|
| 105 |
worker <- structure("remote.example.org", localhost = FALSE) |
| 106 |
options <- makeNodePSOCK(action = "options", worker = worker, port = 12345L, rshcmd = NULL, verbose = TRUE) |
| 107 |
stopifnot(inherits(options, "makeNodePSOCKOptions")) |
| 108 |
|
| 109 |
worker <- structure("remote.example.org", localhost = TRUE) |
| 110 |
options <- makeNodePSOCK(action = "options", worker = worker, port = 12345L, rshcmd = NULL, verbose = TRUE) |
| 111 |
stopifnot(inherits(options, "makeNodePSOCKOptions")) |
| 112 |
|
| 113 |
worker <- "remote.example.org" |
| 114 |
options <- makeNodePSOCK(action = "options", worker = worker, port = 12345L, rshcmd = "<ssh>", verbose = TRUE) |
| 115 |
stopifnot(inherits(options, "makeNodePSOCKOptions")) |
| 116 |
|
| 117 |
worker <- "remote.example.org" |
| 118 |
options <- makeNodePSOCK(action = "options", worker = worker, port = 12345L, rshcmd = "rsh", verbose = TRUE) |
| 119 |
stopifnot(inherits(options, "makeNodePSOCKOptions")) |
| 120 |
|
| 121 |
worker <- "remote.example.org" |
| 122 |
options <- makeNodePSOCK(action = "options", worker = worker, port = 12345L, rshcmd = "unknown", verbose = TRUE) |
| 123 |
stopifnot(inherits(options, "makeNodePSOCKOptions")) |
| 124 |
|
| 125 |
options <- makeNodePSOCK(action = "options", port = 12345L, rshlogfile = FALSE, verbose = TRUE) |
| 126 |
stopifnot(inherits(options, "makeNodePSOCKOptions")) |
| 127 |
|
| 128 |
options <- makeNodePSOCK(action = "options", port = 12345L, rshlogfile = TRUE, verbose = TRUE) |
| 129 |
stopifnot(inherits(options, "makeNodePSOCKOptions")) |
| 130 |
|
| 131 |
options <- makeNodePSOCK(action = "options", port = 12345L, rshlogfile = tempfile(fileext = ".log"), verbose = TRUE) |
| 132 |
stopifnot(inherits(options, "makeNodePSOCKOptions")) |
| 133 |
|
| 134 |
options <- makeNodePSOCK(action = "options", port = 12345L, default_packages = c("*"), verbose = TRUE) |
| 135 |
stopifnot(inherits(options, "makeNodePSOCKOptions")) |
| 136 |
|
| 137 |
oopts <- options(defaultPackages = character(0L)) |
| 138 |
options <- makeNodePSOCK(action = "options", port = 12345L, default_packages = c("*"), verbose = TRUE) |
| 139 |
stopifnot(inherits(options, "makeNodePSOCKOptions")) |
| 140 |
options(oopts) |
| 141 |
|
| 142 |
myrscript <- file.path(R.home("bin"), if (.Platform$OS.type == "windows") "R.exe" else "R") |
| 143 |
options <- makeNodePSOCK(action = "options", port = 12345L, default_packages = c("base"), rscript = myrscript, verbose = TRUE) |
| 144 |
stopifnot(inherits(options, "makeNodePSOCKOptions")) |
| 145 |
|
| 146 |
options <- tryCatch(makeNodePSOCK(action = "options", port = 12345L, default_packages = c("invalid-pkg-name"), verbose = TRUE), error = identity) |
| 147 |
stopifnot(inherits(options, "error")) |
| 148 |
|
| 149 |
|
| 150 |
options <- makeNodePSOCK(action = "options", port = 12345L, rscript = "Rscript") |
| 151 |
stopifnot(inherits(options, "makeNodePSOCKOptions")) |
| 152 |
|
| 153 |
options <- makeNodePSOCK(action = "options", port = 12345L, rscript = "*") |
| 154 |
stopifnot(inherits(options, "makeNodePSOCKOptions")) |
| 155 |
|
| 156 |
options <- makeNodePSOCK(action = "options", port = 12345L, rscript = "*", homogeneous = TRUE) |
| 157 |
stopifnot(inherits(options, "makeNodePSOCKOptions")) |
| 158 |
|
| 159 |
options <- tryCatch(makeNodePSOCK(action = "options", port = 12345L, rscript = "unknown-Rscript-file", homogenous = TRUE), error = identity) |
| 160 |
stopifnot(inherits(options, "error")) |
| 161 |
|
| 162 |
options <- tryCatch(makeNodePSOCK(action = "options", port = 12345L, rscript = 42L, homogenous = TRUE), error = identity) |
| 163 |
stopifnot(inherits(options, "error")) |
| 164 |
|
| 165 |
|
| 166 |
options <- makeNodePSOCK(action = "options", port = 12345L, rscript_startup = "x <- 42") |
| 167 |
stopifnot(inherits(options, "makeNodePSOCKOptions")) |
| 168 |
|
| 169 |
options <- makeNodePSOCK(action = "options", port = 12345L, rscript_startup = list(quote(x <- 42))) |
| 170 |
stopifnot(inherits(options, "makeNodePSOCKOptions")) |
| 171 |
|
| 172 |
|
| 173 |
options <- makeNodePSOCK(action = "options", port = 12345L, rscript_libs = "*") |
| 174 |
stopifnot(inherits(options, "makeNodePSOCKOptions")) |
| 175 |
|
| 176 |
options <- makeNodePSOCK(action = "options", port = 12345L, socketOptions = "NULL") |
| 177 |
stopifnot(inherits(options, "makeNodePSOCKOptions")) |
| 178 |
|
| 179 |
options(parallelly.makeNodePSOCK.rscript_label = TRUE) |
| 180 |
options <- makeNodePSOCK(action = "options", port = 12345L) |
| 181 |
stopifnot(inherits(options, "makeNodePSOCKOptions")) |
| 182 |
options(parallelly.makeNodePSOCK.rscript_label = NULL) |
| 183 |
|
| 184 |
|
| 185 |
options <- makeNodePSOCK(action = "options", port = 12345L, rscript_envs = "USER") |
| 186 |
stopifnot(inherits(options, "makeNodePSOCKOptions")) |
| 187 |
|
| 188 |
options <- makeNodePSOCK(action = "options", port = 12345L, rscript_envs = c(USER = "alice")) |
| 189 |
stopifnot(inherits(options, "makeNodePSOCKOptions")) |
| 190 |
|
| 191 |
options <- makeNodePSOCK(action = "options", port = 12345L, rscript_envs = c("NON-EXISTING-ENVVAR-1234567890" = "abc123")) |
| 192 |
stopifnot(inherits(options, "makeNodePSOCKOptions")) |
| 193 |
|
| 194 |
|
| 195 |
cond <- NULL |
| 196 |
withCallingHandlers({ |
| 197 |
options <- makeNodePSOCK(action = "options", port = 12345L, rscript_envs = "NON-EXISTING-ENVVAR-0987654321") |
| 198 |
}, warning = function(c) { |
| 199 |
cond <<- c |
| 200 |
}) |
| 201 |
stopifnot(inherits(options, "makeNodePSOCKOptions")) |
| 202 |
stopifnot(inherits(cond, "warning")) |
| 203 |
|
| 204 |
options <- tryCatch(makeNodePSOCK(action = "options", port = 12345L, rscript_envs = ""), error = identity) |
| 205 |
stopifnot(inherits(options, "error")) |
| 206 |
|
| 207 |
options <- makeNodePSOCK(action = "options", port = 12345L, rscript_envs = c("ABC" = NA_character_)) |
| 208 |
stopifnot(inherits(options, "makeNodePSOCKOptions")) |
| 209 |
|
| 210 |
|
| 211 |
options <- makeNodePSOCK(action = "options", port = 12345L, calls = TRUE) |
| 212 |
stopifnot(inherits(options, "makeNodePSOCKOptions")) |
| 213 |
|
| 214 |
options <- makeNodePSOCK(action = "options", port = 12345L, rscript_args = "*") |
| 215 |
stopifnot(inherits(options, "makeNodePSOCKOptions")) |
| 216 |
|
| 217 |
options <- makeNodePSOCK(action = "options", port = 12345L, rscript_args = c("first", "*")) |
| 218 |
stopifnot(inherits(options, "makeNodePSOCKOptions")) |
| 219 |
|
| 220 |
options <- makeNodePSOCK(action = "options", port = 12345L, rscript_args = c("first", "*", "last")) |
| 221 |
stopifnot(inherits(options, "makeNodePSOCKOptions")) |
| 222 |
|
| 223 |
options <- tryCatch(makeNodePSOCK(action = "options", port = 12345L, rscript_args = c("*", "*")), error = identity) |
| 224 |
stopifnot(inherits(options, "error")) |
| 225 |
|
| 226 |
options <- makeNodePSOCK(action = "options", port = 12345L, renice = 19L) |
| 227 |
stopifnot(inherits(options, "makeNodePSOCKOptions")) |
| 228 |
|
| 229 |
|
| 230 |
message("*** makeNodePSOCK() ... DONE") |