Skip to content

Commit

Permalink
Try to make tests less flaky
Browse files Browse the repository at this point in the history
  • Loading branch information
jeroen committed Oct 21, 2024
1 parent 6a03fb5 commit dfe4251
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 10 deletions.
2 changes: 1 addition & 1 deletion tests/testthat/test-handle.R
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ test_that("Custom vector options", {
handle_setopt(h, quote = c("bla"))
})

test_that("Custom URL parser", {
test_that("Timeout error includes hostname", {
h <- new_handle(timeout = 1L)
expect_error(curl_fetch_memory('https://httpbin.org/delay/10', handle = h), 'Timeout was reached: [httpbin.org] ', fixed = TRUE)

Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-multi-download.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ context("Multi download")
test_that("Stress test multi_download", {
skip_on_cran()
mirror <- 'https://cloud.r-project.org'
pkgs <- row.names(available.packages(repos = mirror))[1:3000]
pkgs <- row.names(available.packages(repos = mirror))[1:1000]
urls <- sprintf('%s/web/packages/%s/DESCRIPTION', mirror, pkgs)
outdir <- file.path(tempdir(), 'descriptions')
files <- sprintf('%s/%s.txt', outdir, pkgs)
Expand Down
12 changes: 4 additions & 8 deletions tests/testthat/test-multi.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
context("Multi handle")

test_that("Timeout works", {
skip_on_os("solaris")
h1 <- new_handle(url = httpbin("delay/3"))
h1 <- new_handle(url = httpbin("delay/10"))
h2 <- new_handle(url = httpbin("post"), postfields = "bla bla")
h3 <- new_handle(url = "https://urldoesnotexist.xyz", connecttimeout = 1)
h4 <- new_handle(url = "http://localhost:14", connecttimeout = 1)
Expand All @@ -13,12 +12,9 @@ test_that("Timeout works", {
multi_add(h4, pool = m)
rm(h1, h2, h3, h4)
gc()
out <- multi_run(timeout = 2, pool = m)
expect_equal(out, list(success = 1, error = 2, pending = 1))
out <- multi_run(timeout = 0, pool = m)
expect_equal(out, list(success = 0, error = 0, pending = 1))
out <- multi_run(pool = m)
expect_equal(out, list(success = 1, error = 0, pending = 0))
spent <- system.time(out <- multi_run(timeout = 2, pool = m))
expect_lte(out$pending, 2)
expect_lte(spent[['elapsed']], 4)
})

test_that("Callbacks work", {
Expand Down

0 comments on commit dfe4251

Please sign in to comment.