1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
context("Garbage collection")
gc()
h1 <- new_handle()
test <- function(){
pool <- new_pool()
h2 <- new_handle()
cb <- function(...){}
curl_fetch_multi('http://jeroen.github.io/images/frink.png', pool = pool, done = cb, handle = h1)
curl_fetch_multi('http://jeroen.github.io/images/frink.png', pool = pool, done = cb, handle = h2)
return(pool)
}
test_that("Garbage collection works", {
# Should clean 0 handles
pool <- test()
expect_equal(total_handles(), 2L)
multi_run(pool = pool)
gc()
expect_equal(total_handles(), 1L)
})
rm(h1)
test_that("Garbage collection works", {
gc()
expect_equal(total_handles(), 0L)
})
# Test circular GC problems
test2 <- function(){
pool <- new_pool()
cb <- function(...){}
curl_fetch_multi('http://jeroen.github.io/images/frink.png', pool = pool, done = cb)
curl_fetch_multi('http://jeroen.github.io/images/frink.png', pool = pool, done = cb)
}
test_that("Clean up pending requets", {
test2()
gc()
expect_equal(total_handles(), 0L)
})
# Test3 circular GC problems
test3 <- function(){
pool <- new_pool()
curl_fetch_multi('https://cran.r-project.org/src/contrib/stringi_1.1.1.tar.gz', pool = pool)
curl_fetch_multi('https://cran.r-project.org/src/contrib/stringi_1.1.1.tar.gz', pool = pool)
return(pool)
}
test_that("Clean up hanging requests", {
pool <- test3()
expect_equal(total_handles(), 2L)
multi_run(0, pool = pool)
rm(pool)
gc()
expect_equal(total_handles(), 0L)
})
|