Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@
^[\.]?air\.toml$
^\.vscode$
^cran-comments\.md$
^CLAUDE.md$
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ inst/doc
.vscode
air.toml
revdep/
CLAUDE.md
.DS_Store
18 changes: 12 additions & 6 deletions R/daemons.R
Original file line number Diff line number Diff line change
Expand Up @@ -790,15 +790,21 @@ launch_daemons <- function(seq, dots, envir) {
pipe_notify(sock, NULL, add = TRUE)
}

sub_real_port <- function(port, url) sub("(?<=:)0(?![^/])", port, url, perl = TRUE)
sub_real_port <- function(sock, url) {
if (parse_url(url)[["port"]] == "0") {
url <- sub(
"(?<=:)0(?![^/])",
opt(attr(sock, "listener")[[1L]], "tcp-bound-port"),
url,
perl = TRUE
)
}
url
}

create_sock <- function(envir, url, tls) {
sock <- req_socket(url, tls = tls)
listener <- attr(sock, "listener")[[1L]]
url <- opt(listener, "url")
if (parse_url(url)[["port"]] == "0") {
url <- sub_real_port(opt(listener, "tcp-bound-port"), url)
}
url <- sub_real_port(sock, url)
`[[<-`(envir, "cv", cv())
`[[<-`(envir, "sock", sock)
`[[<-`(envir, "url", url)
Expand Down
6 changes: 1 addition & 5 deletions R/dispatcher.R
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,7 @@ dispatcher <- function(host, url = NULL, n = 0L, ...) {
}
} else {
listen(psock, url = url, tls = tls, fail = 2L)
listener <- attr(psock, "listener")[[1L]]
url <- opt(listener, "url")
if (parse_url(url)[["port"]] == "0") {
url <- sub_real_port(opt(listener, "tcp-bound-port"), url)
}
url <- sub_real_port(psock, url)
}
send(sock, url, mode = 2L, block = TRUE)

Expand Down
10 changes: 5 additions & 5 deletions tests/tests.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ test_error(mirai(), "missing expression, perhaps wrap in {}?")
test_error(mirai(a, 1), "all `...` arguments must be named")
test_error(mirai(a, .args = list(1)), "all items in `.args` must be named")
test_error(mirai_map(1:2, identity))
test_error(daemons(url = "URL"), "Invalid argument")
test_error(daemons(url = "URL"))
test_error(daemons(-1), "zero or greater")
test_error(daemons(raw(0L)), "must be numeric")
test_error(daemons(1, dispatcher = ""))
test_error(daemons(url = local_url(), dispatcher = NA))
test_error(daemon("URL"), "Invalid argument")
test_error(daemon("URL"))
test_error(launch_local(1L), "daemons must be set")
test_error(race_mirai(list()), "daemons must be set")
test_false(daemons_set())
Expand Down Expand Up @@ -389,13 +389,13 @@ connection && Sys.getenv("NOT_CRAN") == "true" && {
Sys.sleep(0.1)
test_true(stop_mirai(m2))
test_true(stop_mirai(m1))
test_equal(m2$data, 20L)
test_equal(m1$data, 20L)
test_true(m2$data >= 20L)
test_true(m1$data >= 20L)
test_class("errorValue", mirai(res)[])
m <- mirai_map(1:10, function(x) { Sys.sleep(2); y <<- TRUE })
Sys.sleep(0.1)
s <- stop_mirai(m)
test_equal(sum(unlist(m[])), 200L)
test_true(all(m[] >= 20L))
test_class("errorValue", mirai(y)[])
test_identical(s, !logical(10L))
test_equal(status()$connections, 1L)
Expand Down