library(mirai) nanotest <- function(x) invisible(x || stop("is not TRUE when expected to be TRUE")) nanotestn <- function(x) invisible(is.null(x) || stop("is not NULL when expected to be NULL")) nanotestz <- function(x) invisible(x == 0L || stop("does not equal 0L as expected")) nanotesto <- function(x) invisible(x == 1L || stop("does not equal 1L as expected")) nanotestp <- function(x) invisible(is.character(capture.output(print(x))) || stop("print output of expression cannot be captured as a character value")) nanotesterr <- function(x, e = "") invisible(grepl(e, tryCatch(x, error = identity)[["message"]], fixed = TRUE) || stop("expected error message '", e, "' not generated")) nanotest(is.list(daemons())) nanotestz(daemons()[["connections"]]) nanotestz(daemons()[["daemons"]]) nanotesto(daemons(1L, dispatcher = FALSE)) me <- mirai(mirai::mirai(), .timeout = 2000L) nanotest(is_mirai_error(call_mirai(me)$data) || is_error_value(me$data)) nanotest(!is_mirai_interrupt(me$data)) nanotest(is_error_value(me[["data"]])) nanotestp(me$data) df <- data.frame(a = 1, b = 2) dm <- mirai(as.matrix(df), .args = list(df), .timeout = 2000L) nanotest(is_mirai(call_mirai(dm))) nanotest(!unresolved(dm)) nanotest(is.matrix(dm$data) || is_error_value(dm$data)) nanotestn(stop_mirai(dm)) nanotesto(daemons()[["connections"]]) nanotesto(daemons()[["daemons"]]) nanotestz(daemons(0L)) nanotestz(daemons()[["connections"]]) nanotestz(daemons()[["daemons"]]) nanotesterr(daemons(url = "URL"), "Invalid argument") nanotesterr(daemons(-1), "zero or greater") nanotesterr(daemons(raw(0L)), "must be numeric") nanotesterr(server("URL"), "Invalid argument") nanotesterr(dispatcher(client = "URL"), "at least one") nanotestz(daemons(0L)) nanotest(is_mirai_interrupt(r <- mirai:::mk_interrupt_error())) nanotestp(r) Sys.sleep(1L) n <- 3L m <- mirai({ Sys.sleep(0.1) q <- m + n + 1L q / m }, m = 2L, .args = list(n), .timeout = 2000L) b <- .(m %>>% rnorm() %>>% as.character) b2 <- .(m$data %>>% as.character()) nanotestp(b) nanotest(inherits(call_mirai(m), "mirai")) nanotest(m$data == 3L || is_error_value(m$data)) nanotest(identical(call_mirai(m), m)) nanotest(is_mirai(m)) nanotest(!unresolved(b)) nanotest(!unresolved(b2$data)) nanotest(length(b$data) == 3L) nanotest(is.environment(b) && is.character(b$data)) nanotest(is.environment(b2) && is.character(b2$data)) Sys.sleep(2.2) nanotestp(m) nanotestp(b) `lang obj` <- quote(m + n + 2L) args <- list(m = 2L, n = 4L) m <- mirai(.expr = `lang obj`, .args = args, .timeout = 2000L) nanotest(call_mirai(m)$data == 8L || is_error_value(m$data)) Sys.sleep(2.2) nanotest(daemons(url = value <- mirai:::auto_tokenized_url(), dispatcher = FALSE) == value) nanotestz(daemons(0L)) Sys.sleep(1L) nanotesto(daemons(1L, dispatcher = FALSE, idletime = 500L, timerstart = 1L, cleanup = 0L, .compute = "new")) Sys.sleep(2L) mn <- mirai("test1", .compute = "new") mp <- mirai("test2", .compute = "new") Sys.sleep(1L) nanotest(mn$data == "test1" || unresolved(mn$data)) nanotest(mp$data == "test2" || unresolved(mp$data)) Sys.sleep(1L) nanotest(daemons(.compute = "new")[["connections"]] == 0L) nanotestz(daemons(0L, .compute = "new")) Sys.sleep(1L) if (.Platform[["OS.type"]] != "windows") { nanotest(daemons(n = 2L, url = value <- "ws://:0", dispatcher = FALSE) != value) nanotestz(daemons(0L)) Sys.sleep(0.5) nanotesto(daemons(url = "ws://:0", token = TRUE)) nanotestz(daemons(0L)) Sys.sleep(1L) nanotesto(daemons(url = "tcp://:0", token = TRUE)) nanotestz(daemons(0L)) Sys.sleep(1L) nanotest(daemons(n = 2, "ws://:0") == 2L) Sys.sleep(1L) status <- daemons()[["daemons"]] nanotest(is.matrix(status) || is_error_value(status)) if (is.matrix(status)) { nanotest(is.character(dn1 <- dimnames(status)[[1L]])) nanotest(is.character(parse1 <- nanonext::parse_url(dn1[1L]))) nanotest(is.character(parse2 <- nanonext::parse_url(dn1[2L]))) nanotest((port <- as.integer(parse1[["port"]])) > 0L) nanotest(as.integer(parse2[["port"]]) == port) nanotest(parse1[["path"]] == "/1") nanotest(parse2[["path"]] == "/2") nanotestz(sum(status[, "online"])) nanotestz(sum(status[, "instance"])) nanotestz(sum(status[, "assigned"])) nanotestz(sum(status[, "complete"])) } nanotest(is.character(saisei(i = 1L))) nanotestn(saisei(i = 10L)) Sys.sleep(0.5) nanotestz(daemons(0)) Sys.sleep(1L) nanotest(daemons(n = 2, "tcp://:0") == 2L) Sys.sleep(1L) nanotest(is.integer(launch_server(mirai:::..[["default"]][["urls"]][1L], maxtasks = 1L))) Sys.sleep(1L) tstatus <- daemons()[["daemons"]] nanotest(is.matrix(tstatus) || is_error_value(tstatus)) if (is.matrix(tstatus)) { nanotest(is.character(tdn1 <- dimnames(tstatus)[[1L]])) nanotest(is.character(tparse1 <- nanonext::parse_url(tdn1[1L]))) nanotest(is.character(tparse2 <- nanonext::parse_url(tdn1[2L]))) nanotest((tport <- as.integer(tparse1[["port"]])) > 0L) nanotest(as.integer(tparse2[["port"]]) != tport) nanotestz(sum(tstatus[, "online"])) nanotestz(sum(tstatus[, "instance"])) nanotestz(sum(tstatus[, "assigned"])) nanotestz(sum(tstatus[, "complete"])) } nanotestz(daemons(0)) Sys.sleep(1L) } if (Sys.getenv("NOT_CRAN") == "true" && .Platform[["OS.type"]] != "windows") { option <- 15L nanotesto(daemons(1, dispatcher = TRUE, maxtasks = 10L, timerstart = 1L, walltime = 2000L, token = TRUE, lock = TRUE, cleanup = option)) Sys.sleep(1L) mq <- mirai("server", .timeout = 1000) nanotest(call_mirai(mq)$data == "server" || is_error_value(mq$data)) dstatus <- daemons()[["daemons"]] nanotest(is.matrix(dstatus) || is_error_value(dstatus)) if (is.matrix(dstatus)) { nanotest(is.integer(dstatus[, "online"])) nanotest(is.integer(dstatus[, "instance"])) } nanotestz(daemons(0)) Sys.sleep(2L) }