Skip to content

Commit

Permalink
Add multiple attempts to ids_bulk test
Browse files Browse the repository at this point in the history
  • Loading branch information
christophscheuch committed Nov 14, 2024
1 parent 07b9405 commit 9f9b6d9
Showing 1 changed file with 33 additions and 7 deletions.
40 changes: 33 additions & 7 deletions tests/testthat/test-ids_bulk.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ options(timeout = 60)

test_that("ids_bulk handles custom file paths", {
skip_if_offline()
skip_on_cran()

test_url <- ids_bulk_files()$file_url[1]
temp_path <- tempfile(fileext = ".xlsx")
Expand Down Expand Up @@ -52,6 +53,9 @@ test_that("ids_bulk requires readxl package", {
})

test_that("ids_bulk handles message parameter correctly", {
skip_if_offline()
skip_on_cran()

test_url <- ids_bulk_files()$file_url[1]

mock_data <- tibble::tibble(
Expand Down Expand Up @@ -104,13 +108,35 @@ test_that("ids_bulk handles timeout parameter correctly", {
check_interactive = function() FALSE
)

expect_warning(
expect_error(
ids_bulk(mock_url, timeout = 1, warn_size = FALSE),
"cannot open URL|Download timed out"
),
"Timeout of 1 seconds was reached"
)
# Retry logic to handle occasional 504 errors
attempt <- 1
max_attempts <- 5
success <- FALSE

while (!success && attempt <= max_attempts) {
attempt <- attempt + 1

result <- tryCatch({
expect_warning(
expect_error(
ids_bulk(mock_url, timeout = 1, warn_size = FALSE),
"cannot open URL|Download timed out"
),
"Timeout of 1 seconds was reached"
)
success <- TRUE
}, error = function(e) {
if (grepl("HTTP 504 Gateway Timeout",
e$message) && attempt <= max_attempts) {
message("Retrying due to 504 Gateway Timeout...")
return(NULL)

Check warning on line 132 in tests/testthat/test-ids_bulk.R

View workflow job for this annotation

GitHub Actions / lint

file=tests/testthat/test-ids_bulk.R,line=132,col=9,[return_linter] Use implicit return behavior; explicit return() is not needed.
} else {
stop(e)
}
})
}
expect_true(success,
info = "Test failed due to repeated 504 Gateway Timeout errors.")
})

test_that("ids_bulk handles warn_size parameter", {
Expand Down

0 comments on commit 9f9b6d9

Please sign in to comment.