@@ -126,26 +126,22 @@ test_that("$files is ordered by key if timestamps are identical", {
126126
127127
128128
129- test_that(" pruning by size works" , {
129+ test_that(" pruning by size works, even if timestamps are identical " , {
130130 td <- file.path(tempdir(), " cache-test" )
131131 on.exit(unlink(td , recursive = TRUE ))
132132
133133 # When using a real hash function as hashfun, identical objects will only
134134 # be added to the cache once
135135 cache <- Cache $ new(td , hashfun = function (x ) ascending_id())
136- cache $ push(iris )
137- Sys.sleep(0.1 )
138- cache $ push(iris )
139- Sys.sleep(0.1 )
140- cache $ push(iris )
141- Sys.sleep(0.1 )
142- cache $ push(iris )
143- Sys.sleep(0.1 )
144- cache $ push(iris )
145- Sys.sleep(0.1 )
136+ for (i in 1 : 5 ) cache $ push(iris )
146137 cache $ push(cars )
147138 expect_identical(cache $ n , 6L )
148139
140+
141+ for (p in cache $ files $ path ){ # loop necessary for compat with R < 3.6.0
142+ Sys.setFileTime(p , " 1999-01-01 00:00:00" )
143+ }
144+
149145 expect_true(cache $ size > 2048 )
150146 cache $ prune(max_size = " 2kb" )
151147 expect_true(cache $ size < = 2048 )
@@ -165,16 +161,7 @@ test_that("Inf max_* do not prunes", {
165161 # When using a real hash function as hashfun, identical objects will only
166162 # be added to the cache once
167163 cache <- Cache $ new(td , hashfun = function (x ) ascending_id())
168- cache $ push(iris )
169- Sys.sleep(0.1 )
170- cache $ push(iris )
171- Sys.sleep(0.1 )
172- cache $ push(iris )
173- Sys.sleep(0.1 )
174- cache $ push(iris )
175- Sys.sleep(0.1 )
176- cache $ push(iris )
177- Sys.sleep(0.1 )
164+ for (i in 1 : 5 ) cache $ push(iris )
178165 cache $ push(cars )
179166 expect_identical(cache $ n , 6L )
180167
@@ -232,16 +219,7 @@ test_that("pruning by age works", {
232219
233220 cache <- MockCache $ new(dir = td , hashfun = function (x ) ascending_id())
234221 on.exit(cache $ purge(), add = TRUE )
235- cache $ push(iris )
236- Sys.sleep(0.1 )
237- cache $ push(iris )
238- Sys.sleep(0.1 )
239- cache $ push(iris )
240- Sys.sleep(0.1 )
241- cache $ push(iris )
242- Sys.sleep(0.1 )
243- cache $ push(iris )
244- Sys.sleep(0.1 )
222+ for (i in 1 : 5 ) cache $ push(iris )
245223
246224 expect_identical(nrow(cache $ files ), 5L )
247225
0 commit comments