| 1 |
test_that("Support preconfigured handles", { |
| 2 |
expect_error(multi_download(new_handle()), 'no URL') |
| 3 |
expect_error(multi_download(new_handle(url = 'https://www.google.com')), 'filename') |
| 4 |
h1 <- new_handle(url = httpbin("html")) |
| 5 |
h2 <- new_handle(url = httpbin("robots.txt")) |
| 6 |
df <- multi_download(c(h1, h2), progress = FALSE) |
| 7 |
expect_equal(df$destfile, normalizePath(c('html', 'robots.txt'))) |
| 8 |
expect_equal(df$status_code, c(200, 200)) |
| 9 |
unlink(c('html', 'robots.txt')) |
| 10 |
}) |
| 11 |
|
| 12 |
|
| 13 |
test_that("Stress test multi_download", { |
| 14 |
skip_on_cran() |
| 15 |
mirror <- 'https://cloud.r-project.org' |
| 16 |
pkgs <- row.names(available.packages(repos = mirror))[1:1000] |
| 17 |
urls <- sprintf('%s/web/packages/%s/DESCRIPTION', mirror, pkgs) |
| 18 |
outdir <- file.path(tempdir(), 'descriptions') |
| 19 |
files <- sprintf('%s/%s.txt', outdir, pkgs) |
| 20 |
dir.create(outdir, showWarnings = FALSE) |
| 21 |
multiplex <- .Platform$OS.type != 'windows' #disable windows multiplex until we fix #379 |
| 22 |
results <- curl::multi_download(urls, files, multi_timeout = 60, connecttimeout=60, |
| 23 |
progress = FALSE, multiplex = multiplex) |
| 24 |
expect_length(results$success, length(pkgs)) |
| 25 |
expect_true(all(results$success)) |
| 26 |
expect_true(all(results$status_code == 200)) |
| 27 |
expect_true(all(file.exists(results$destfile))) |
| 28 |
unlink(results$destfile) |
| 29 |
}) |