Skip to content

Commit

Permalink
Test: add test for task execution errors
Browse files Browse the repository at this point in the history
  • Loading branch information
mihaiconstantin committed May 7, 2023
1 parent 0b7276d commit a98624f
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions tests/testthat/helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,12 @@ tests_set_for_synchronous_backend_operations <- function(service, specification,
# Tests for the `sapply` operation.
tests_set_for_synchronous_backend_task_execution(operation, service, expected_output)

# Expect that errors in the task executed via `sapply` are propagated.
expect_error(
service$sapply(1:10, function(x) stop("Task error.")),
"Task error."
)

# Created the expect output.
expected_output <- as.list(expected_output)

Expand All @@ -243,6 +249,12 @@ tests_set_for_synchronous_backend_operations <- function(service, specification,
# Tests for the `lapply` operation.
tests_set_for_synchronous_backend_task_execution(operation, service, expected_output)

# Expect that errors in the task executed via `lapply` are propagated.
expect_error(
service$lapply(1:10, function(x) stop("Task error.")),
"Task error."
)

# Redefine `x` as a matrix for the `apply` operation.
x <- matrix(rnorm(100^2), nrow = 100, ncol = 100)

Expand Down Expand Up @@ -297,6 +309,12 @@ tests_set_for_synchronous_backend_operations <- function(service, specification,
fixed = TRUE
)

# Expect that errors in the task executed via `apply` are propagated.
expect_error(
service$apply(matrix(1:100, 10, 10), 1, function(x) stop("Task error.")),
"Task error."
)

# Expect that the cluster is empty after performing operations on it.
expect_true(all(sapply(service$peek(), length) == 0))

Expand Down Expand Up @@ -390,6 +408,15 @@ tests_set_for_asynchronous_backend_operations <- function(service, specification
# Tests for the `sapply` operation.
tests_set_for_asynchronous_backend_task_execution(operation, service, expected_output)

# Expect that errors in the task executed via `sapply` are propagated.
expect_error(
{
service$sapply(1:10, function(x) stop("Task error."))
service$get_output(wait = TRUE)
},
"Task error."
)

# Compute the expected output for the `lapply` operation.
expected_output <- as.list(expected_output)

Expand All @@ -399,6 +426,15 @@ tests_set_for_asynchronous_backend_operations <- function(service, specification
# Tests for the `lapply` operation.
tests_set_for_asynchronous_backend_task_execution(operation, service, expected_output)

# Expect that errors in the task executed via `lapply` are propagated.
expect_error(
{
service$lapply(1:10, function(x) stop("Task error."))
service$get_output(wait = TRUE)
},
"Task error."
)

# Redefine `x` as a matrix for the `apply` operation.
x <- matrix(rnorm(100^2), nrow = 100, ncol = 100)

Expand Down Expand Up @@ -453,6 +489,15 @@ tests_set_for_asynchronous_backend_operations <- function(service, specification
fixed = TRUE
)

# Expect that errors in the task executed via `apply` are propagated.
expect_error(
{
service$apply(matrix(1:100, 10, 10), 1, function(x) stop("Task error."))
service$get_output(wait = TRUE)
},
"Task error."
)

# Expect that the cluster is empty after performing operations on it.
expect_true(all(sapply(service$peek(), length) == 0))

Expand Down

0 comments on commit a98624f

Please sign in to comment.