Skip to content

Commit 5585070

Browse files
TESTS: Increase test coverage
1 parent a0ed4a6 commit 5585070

File tree

1 file changed

+171
-0
lines changed

1 file changed

+171
-0
lines changed

inst/testme/test-makeNodePSOCK.R

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,175 @@ options <- makeNodePSOCK(port = 12345L, default_packages = c("stats", "*"), acti
5656
print(options)
5757
stopifnot(inherits(options, "makeNodePSOCKOptions"))
5858

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+
59230
message("*** makeNodePSOCK() ... DONE")

0 commit comments

Comments
 (0)