Skip to content

Commit

Permalink
Update tally() tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wlandau-lilly committed Sep 20, 2023
1 parent 8422cec commit 1e55e2f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 18 deletions.
9 changes: 5 additions & 4 deletions R/crew_launcher.R
Original file line number Diff line number Diff line change
Expand Up @@ -466,11 +466,10 @@ crew_class_launcher <- R6::R6Class(
#' should not set this.
tally = function(daemons = NULL) {
daemons <- daemons %|||% daemons_info(name = self$name)
index <- !(self$workers$launched)
self$workers$online <- as.logical(daemons[, "online"])
self$workers$discovered <- as.logical(daemons[, "instance"] > 0L)
self$workers$assigned[index] <- as.integer(daemons[index, "assigned"])
self$workers$complete[index] <- as.integer(daemons[index, "complete"])
self$workers$assigned <- as.integer(daemons[, "assigned"])
self$workers$complete <- as.integer(daemons[, "complete"])
invisible()
},
#' @description Get workers available for launch.
Expand Down Expand Up @@ -509,7 +508,9 @@ crew_class_launcher <- R6::R6Class(
"launched",
self$launch_max,
"times in a row without completing any tasks. Either raise",
"launch_max or troubleshoot your platform to figure out",
"launch_max above",
self$launch_max,
"or troubleshoot your platform to figure out",
"why {crew} workers are not launching or connecting."
)
)
Expand Down
6 changes: 3 additions & 3 deletions tests/interactive/test-launch_max.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ x$start()
expect_equal(x$launcher$workers$futile, 0L)
x$launch(n = 1L)
# Pause until worker idles out.
expect_equal(x$launcher$workers$futile, 1L)
expect_equal(x$launcher$workers$futile, 0L)
x$launch(n = 1L)
# Pause until worker idles out.
expect_equal(x$launcher$workers$futile, 2L)
expect_equal(x$launcher$workers$futile, 1L)
x$launcher$seconds_idle <- Inf
x$push(TRUE)
x$wait()
expect_equal(x$launcher$workers$futile, 3L)
expect_equal(x$launcher$workers$futile, 2L)
x$launcher$terminate(1L)
# Pause until worker exits.
x$launcher$seconds_idle <- 1e-9
Expand Down
17 changes: 6 additions & 11 deletions tests/testthat/test-crew_launcher.R
Original file line number Diff line number Diff line change
Expand Up @@ -210,23 +210,18 @@ crew_test("launcher tally()", {
launcher$start(sockets = rep("x", nrow(grid)))
launcher$workers$launched <- grid$launched
daemons <- cbind(
online = rep(0L, nrow(grid)),
instance = rep(0L, nrow(grid)),
online = c(1L, 1L, 0L, 0L),
instance = c(1L, 0L, 1L, 0L),
assigned = rep(7L, nrow(grid)),
complete = grid$complete
)
expect_equal(launcher$workers$online, rep(FALSE, nrow(grid)))
expect_equal(launcher$workers$discovered, rep(FALSE, nrow(grid)))
expect_equal(launcher$workers$assigned, rep(0L, nrow(grid)))
expect_equal(launcher$workers$complete, rep(0L, nrow(grid)))
launcher$tally(daemons = daemons)
expect_equal(launcher$workers$assigned, c(0L, 0L, 7L, 7L))
expect_equal(launcher$workers$complete, c(0L, 0L, 3L, 7L))
launcher$workers$launched[1L] <- FALSE
launcher$workers$launched[4L] <- TRUE
launcher$tally(daemons = daemons)
expect_equal(launcher$workers$assigned, c(7L, 0L, 7L, 7L))
expect_equal(launcher$workers$complete, c(3L, 0L, 3L, 7L))
launcher$workers$launched <- !(launcher$workers$launched)
launcher$tally(daemons = daemons)
expect_equal(launcher$workers$online, c(TRUE, TRUE, FALSE, FALSE))
expect_equal(launcher$workers$discovered, c(TRUE, FALSE, TRUE, FALSE))
expect_equal(launcher$workers$assigned, c(7L, 7L, 7L, 7L))
expect_equal(launcher$workers$complete, c(3L, 7L, 3L, 7L))
})
Expand Down

0 comments on commit 1e55e2f

Please sign in to comment.