Skip to content

Commit cf38149

Browse files
author
Stefan Fleck
committed
resubmission that hopefully fixes sort order of files in cache on systems with low-accuracy timestamp
1 parent 28d1436 commit cf38149

4 files changed

Lines changed: 32 additions & 30 deletions

File tree

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Type: Package
22
Package: rotor
33
Title: Log Rotation and Conditional Backups
4-
Version: 0.3.1
4+
Version: 0.3.2
55
Authors@R:
66
person(given = "Stefan",
77
family = "Fleck",

R/Cache.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,8 @@ Cache <- R6::R6Class(
333333
)
334334
row.names(res) <- NULL
335335

336-
res[order(res$mtime), ]
336+
assert(!is.null(res$mtime))
337+
res[order(res$mtime, res$key), ]
337338
},
338339

339340
size = function(){

cran-comments.md

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,12 @@
1010

1111
0 errors | 0 warnings | 0 notes
1212

13-
* fixes time zone related issue in `Cache$prune()` that causes macOS tests to fail
14-
* more robust cleanup of temporary files between some tests
15-
* resubmission that improves one test where
16-
`https://cran.r-project.org/web/checks/check_results_rotor.html` shows an
17-
error that I could not reproduce on any machine available on rhub.
18-
Hopefully the test succeedes now, but if not it will give me more useful
19-
debug information for another resubmission.
13+
Sorry for the many resubmissions. This package currently has an issue that
14+
only to occur on macOS. It does not occur on the same macOS version available
15+
on Rhub.
2016

21-
22-
Notes:
23-
24-
There was a timezone related issue that only occured on macos. I fixed it and
25-
was able to test it on macOS 10.13.6 High Sierra with R-release (but not devel)
26-
on Rhub.
27-
28-
I could not reproduce the other errors; however, it looks as if they were caused
29-
by improperly cleaned-up temporary files between failing tests. I made the
30-
cleanup code a bit more robust and hope the problem is fixed now.
17+
My current theory is that the error is caused by the accuracy of the
18+
'mtime' filestamp, which is linked to the file system the machine uses.
19+
I implemented a workaround under that assumption, but I cannot be 100% sure
20+
that this fixes that error. If the error still persists... could you please
21+
inform me which file system you use on r-release-macos-x86_64?

tests/testthat/test_Cache.R

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
11
context("Cache")
22

33

4+
# generate lexically sortable ids. For equal timestamp, Cache$files is sorted
5+
# by id, so that the tests do not fail on file systems with low-accuracy
6+
# timestamps
7+
8+
9+
.id_cache <- new.env()
10+
assign("id", 0L, .id_cache)
11+
ascending_id <- function(){
12+
x <- get("id", .id_cache)
13+
x <- as.character(as.integer(x) + 1L)
14+
assign("id", x, .id_cache)
15+
x
16+
}
17+
18+
419
test_that("Cache works as expected", {
520
td <- file.path(tempdir(), "cache-test")
621
on.exit(unlink(td, recursive = TRUE))
@@ -47,14 +62,14 @@ test_that("setting hash functions work", {
4762

4863

4964
# To override this behaviour use a generate for unique ids, such as
50-
cache_uid <- Cache$new(td, hashfun = function(x) uuid::UUIDgenerate())
65+
cache_uid <- Cache$new(td, hashfun = function(x) ascending_id())
5166
cache_uid$push(iris)
5267
cache_uid$push(iris)
5368
expect_identical(cache_hash$n, 2L)
5469
cache_hash$purge()
5570

5671
# ensure hashfun allways returns a scalar
57-
cache_err <- Cache$new(td, hashfun = function(x) uuid::UUIDgenerate(n = 2))
72+
cache_err <- Cache$new(td, hashfun = function(x) c(ascending_id(), ascending_id()))
5873
expect_error(cache_err$push(iris), class = "ValueError")
5974
})
6075

@@ -66,13 +81,9 @@ test_that("pruning works by number of files works", {
6681
td <- file.path(tempdir(), "cache-test")
6782
on.exit(unlink(td, recursive = TRUE))
6883

69-
# When using a real hash function as hashfun, identical objects will only
70-
# be added to the cache once
71-
cache <- Cache$new(td, hashfun = function(x) uuid::UUIDgenerate())
84+
cache <- Cache$new(td, hashfun = function(x) ascending_id())
7285
k1 <- cache$push(iris)
73-
Sys.sleep(1)
7486
k2 <- cache$push(letters)
75-
Sys.sleep(1)
7687
k3 <- cache$push(cars)
7788
expect_identical(cache$n, 3L)
7889

@@ -81,7 +92,6 @@ test_that("pruning works by number of files works", {
8192
expect_identical(cache$files$key[[3]], k3)
8293

8394
cache$prune(max_files = 2)
84-
cache$files
8595
expect_identical(cache$read(cache$files$key[[1]]), letters)
8696
expect_identical(cache$read(cache$files$key[[2]]), cars)
8797
cache$purge()
@@ -96,7 +106,7 @@ test_that("pruning by size works", {
96106

97107
# When using a real hash function as hashfun, identical objects will only
98108
# be added to the cache once
99-
cache <- Cache$new(td, hashfun = function(x) uuid::UUIDgenerate())
109+
cache <- Cache$new(td, hashfun = function(x) ascending_id())
100110
cache$push(iris)
101111
Sys.sleep(0.1)
102112
cache$push(iris)
@@ -128,7 +138,7 @@ test_that("Inf max_* do not prunes", {
128138

129139
# When using a real hash function as hashfun, identical objects will only
130140
# be added to the cache once
131-
cache <- Cache$new(td, hashfun = function(x) uuid::UUIDgenerate())
141+
cache <- Cache$new(td, hashfun = function(x) ascending_id())
132142
cache$push(iris)
133143
Sys.sleep(0.1)
134144
cache$push(iris)
@@ -194,7 +204,7 @@ test_that("pruning by age works", {
194204
)
195205
)
196206

197-
cache <- MockCache$new(dir = td, hashfun = function(x) uuid::UUIDgenerate())
207+
cache <- MockCache$new(dir = td, hashfun = function(x) ascending_id())
198208
on.exit(cache$purge(), add = TRUE)
199209
cache$push(iris)
200210
Sys.sleep(0.1)

0 commit comments

Comments
 (0)