Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add multiple attempts to ids_bulk test for handling timeout parameter #37

Merged
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
39 changes: 32 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,34 @@ 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...")
} 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