| 1 |
test_that("File writer is properly cleaned", { |
| 2 |
fp1 <- file_writer(tempfile()) |
| 3 |
fp2 <- file_writer(tempfile()) |
| 4 |
expect_equal(total_writers(), 0) |
| 5 |
fp1(raw(5)) |
| 6 |
fp1(raw(10)) |
| 7 |
expect_equal(total_writers(), 1) |
| 8 |
fp2(raw(5)) |
| 9 |
fp2(raw(10)) |
| 10 |
gc() |
| 11 |
expect_equal(total_writers(), 2) |
| 12 |
fp2(raw(0), close = TRUE) |
| 13 |
expect_equal(total_writers(), 1) |
| 14 |
rm(fp1); gc() |
| 15 |
expect_equal(total_writers(), 0) |
| 16 |
}) |
| 17 |
|
| 18 |
test_that("File writer is closed at the end of the data callback", { |
| 19 |
pool <- new_pool() |
| 20 |
tmp <- tempfile() |
| 21 |
on.exit(unlink(tmp)) |
| 22 |
curl_fetch_multi(httpbin("get"), data = tmp, pool = pool) |
| 23 |
expect_equal(total_writers(), 0) |
| 24 |
multi_run(pool = pool) |
| 25 |
expect_equal(total_writers(), 0) |
| 26 |
json <- readLines(tmp) |
| 27 |
expect_true(jsonlite::validate(json)) |
| 28 |
}) |