Skip to content

Commit d02616a

Browse files
committed
calirfy in the help that age and size are connected with AND in rotate_time and rotate_date, added more tests for that behaviour
1 parent 45540a1 commit d02616a

File tree

5 files changed

+91
-6
lines changed

5 files changed

+91
-6
lines changed

R/rotate.R

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
#' a fixed point in time after which to backup/rotate. See `format` for
1414
#' which Date/Datetime formats are supported by rotor.
1515
#'
16+
#' (if `age` *and* `size` are provided, both criteria must be `TRUE` to
17+
#' trigger rotation)
1618
#' @param format a scalar `character` that can be a subset of of valid
1719
#' `strftime()` formatting strings. The default setting is
1820
#' `"%Y-%m-%d--%H-%M-%S"`.
@@ -51,6 +53,9 @@
5153
#' `KiB`, `MiB`, `GiB`, `TiB`. In Both cases `1` kilobyte is `1024` bytes, 1
5254
#' `megabyte` is `1024` kilobytes, etc... .
5355
#'
56+
#' (if `age` *and* `size` are provided, both criteria must be `TRUE` to
57+
#' trigger rotation)
58+
#'
5459
#' @param dir `character` scalar. The directory in which the backups
5560
#' of `file` are stored (defaults to `dirname(file)`)
5661
#'

man/Cache.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/rotate.Rd

Lines changed: 8 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/rotate_rds.Rd

Lines changed: 8 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test_BackupQueue.R

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,13 +562,31 @@ test_that("BackupQueueIndex: $prune_identical works", {
562562

563563

564564

565+
test_that("BackupQueueIndex: rotations trigger as expected", {
566+
dir.create(td, recursive = TRUE)
567+
on.exit(unlink(td, recursive = TRUE))
568+
569+
tf <- file.path(td, "test")
570+
saveRDS(iris, tf)
571+
on.exit(unlink(tf), add = TRUE)
572+
bq <- BackupQueueIndex$new(tf)
573+
574+
# size threshold is not met
575+
expect_false(bq$should_rotate(size = file.size(tf) + 1))
576+
577+
# size threshold is met
578+
expect_true(bq$should_rotate(size = file.size(tf) / 2))
579+
})
580+
581+
582+
565583
# BackupQueueDateTime -----------------------------------------------------
566584
context("BackupQueueDateTime")
567585

568586

569587

570588

571-
test_that("BackupQueueDatetime: backups_cache", {
589+
test_that("BackupQueueDatetime: Caching the last rotation date works (cache_backups = TRUE)", {
572590
dir.create(td, recursive = TRUE)
573591
on.exit(unlink(td, recursive = TRUE))
574592

@@ -945,6 +963,31 @@ test_that("BackupQueueDateTime: $should_rotate(verbose = TRUE) displays helpful
945963

946964

947965

966+
test_that("BackupQueueDateTime: rotations trigger as expected", {
967+
dir.create(td, recursive = TRUE)
968+
on.exit(unlink(td, recursive = TRUE))
969+
970+
tf <- file.path(td, "test")
971+
saveRDS(iris, tf)
972+
on.exit(unlink(tf), add = TRUE)
973+
bq <- BackupQueueDateTime$new(tf)
974+
975+
fake_time <- as.POSIXct("2020-01-01 01:00:00")
976+
977+
# neither age nor size threshold is met
978+
expect_false(bq$should_rotate(size = file.size(tf) + 1, age = Inf))
979+
980+
# size threshold is met but not age
981+
expect_false(bq$should_rotate(size = file.size(tf) / 2, age = "2 days", now = as.POSIXct("2020-01-01 02:00:00"), last_rotation = fake_time))
982+
983+
# age threshold is met but not size
984+
expect_false(bq$should_rotate(size = file.size(tf) + 1, age = "2 days", now = as.POSIXct("2020-01-04 02:00:00"), last_rotation = fake_time))
985+
986+
# both criteria are met
987+
expect_true(bq$should_rotate(size = file.size(tf) / 2, age = "2 days", now = as.POSIXct("2020-01-06 02:00:00"), last_rotation = fake_time))
988+
})
989+
990+
948991
# BackupQueueDate ---------------------------------------------------------
949992
context("BackupQueueDate")
950993

@@ -1342,6 +1385,31 @@ test_that("BackupQueueDate: $should_rotate(verbose = TRUE) displays helpful mess
13421385

13431386

13441387

1388+
test_that("BackupQueueDate: rotations trigger as expected", {
1389+
dir.create(td, recursive = TRUE)
1390+
on.exit(unlink(td, recursive = TRUE))
1391+
1392+
tf <- file.path(td, "test")
1393+
saveRDS(iris, tf)
1394+
on.exit(unlink(tf), add = TRUE)
1395+
bq <- BackupQueueDate$new(tf)
1396+
1397+
fake_time <- as.POSIXct("2020-01-01 01:00:00")
1398+
1399+
# neither age nor size threshold is met
1400+
expect_false(bq$should_rotate(size = file.size(tf) + 1, age = Inf))
1401+
1402+
# size threshold is met but not age
1403+
expect_false(bq$should_rotate(size = file.size(tf) / 2, age = "2 days", now = as.POSIXct("2020-01-01 02:00:00"), last_rotation = fake_time))
1404+
1405+
# age threshold is met but not size
1406+
expect_false(bq$should_rotate(size = file.size(tf) + 1, age = "2 days", now = as.POSIXct("2020-01-04 02:00:00"), last_rotation = fake_time))
1407+
1408+
# both criteria are met
1409+
expect_true(bq$should_rotate(size = file.size(tf) / 2, age = "2 days", now = as.POSIXct("2020-01-06 02:00:00"), last_rotation = fake_time))
1410+
})
1411+
1412+
13451413
# cleanup -----------------------------------------------------------------
13461414

13471415
test_that("BackupQueue: all cleanup succesfull", {

0 commit comments

Comments
 (0)