Skip to content

Commit b69ca26

Browse files
committed
Another attempt to fix low precision file systems
1 parent 6228bd9 commit b69ca26

File tree

7 files changed

+20
-40
lines changed

7 files changed

+20
-40
lines changed

CRAN-RELEASE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
This package was submitted to CRAN on 2020-10-27.
2+
Once it is accepted, delete this file and tag the release (commit 8fc994e32d).

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.3
4+
Version: 0.3.4
55
Authors@R:
66
person(given = "Stefan",
77
family = "Fleck",

NEWS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# rotor 0.3.4
2+
3+
* Further fixes for the issue mentioned in 0.3.3
4+
15
# rotor 0.3.3
26

37
* Hotfix for some tests related to the `Cache` R6 class that fail on systems

R/Cache.R

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,7 @@ Cache <- R6::R6Class(
162162

163163
if (!is.null(max_size) && !is.infinite(max_size)){
164164
max_size <- parse_size(max_size)
165-
files <- files[order(files$mtime, decreasing = TRUE), ]
166-
files$cumsize <- cumsum(files$size)
165+
files$cumsize <- rev(cumsum(rev(files$size)))
167166
rem$size <- files[files$cumsize > max_size, ]
168167
}
169168

cran-comments.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,5 @@
1010

1111
0 errors | 0 warnings | 0 notes
1212

13-
Another - hopefully final attempt - to fix a hard to debug issue where some
14-
tests can fail on systems with low-precission filesystem-timestamps
15-
(such as ext3 and old Windows filesystems).
16-
17-
Added a test that mocks low-precision filesystem-timestamps to be on the safe
18-
side.
13+
More fixes for file-system timestamp related bugs that I could not reproduce on
14+
my test systems. Sorry again for all the trouble.

tests/testthat/test_BackupQueue.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,7 @@ test_that("BackupQueueIndex$push() can push to different directory", {
458458

459459

460460
test_that("BackupQueueIndex dry run doesnt modify file system", {
461+
try({unlink(td, recursive = TRUE)})
461462
dir.create(td, recursive = TRUE)
462463
on.exit(unlink(td, recursive = TRUE))
463464

tests/testthat/test_Cache.R

Lines changed: 9 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)