Debian Codegraph @

tests/testthat/test-gc.R

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