Skip to content

Commit f9a170a

Browse files
committed
fix: fix unit tests based on the changed defaults
1 parent b12c90d commit f9a170a

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

R/retry_download.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#' Retry an expression `ntimes` times waiting an increasing amount of time
2-
#' between tries, i.e. waiting for `Sys.sleep(i * sleep_mult)` seconds between
2+
#' between tries, i.e., waiting for `Sys.sleep(i * sleep_mult)` seconds between
33
#' each try. If `expr` fails for `ntimes` times the error will be thrown.
44
#'
55
#' @param expr Expression to be evaluated.
@@ -18,7 +18,7 @@
1818
#' @importFrom methods is
1919
#'
2020
#' @noRd
21-
.retry <- function(expr, ntimes = 5, sleep_mult = 0) {
21+
.retry <- function(expr, ntimes = 5L, sleep_mult = 0L) {
2222
res <- NULL
2323
for (i in seq_len(ntimes)) {
2424
res <- suppressWarnings(tryCatch(expr, error = function(e) e))
@@ -32,5 +32,5 @@
3232
}
3333

3434
.sleep_mult <- function() {
35-
as.integer(getOption("metabolights.sleep_mult", default = 7))
35+
as.integer(getOption("metabolights.sleep_mult", default = 7L))
3636
}

tests/testthat/test_retry_download.R

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ test_that(".retry works", {
44
stop("A, got a 0")
55
1
66
}
7-
87
set.seed(123)
9-
expect_error(.retry(a()), "A, got a 0")
10-
res <- .retry(a())
8+
res <- .retry(a(), ntimes = 5L)
119
expect_equal(res, 1)
10+
## Failure
11+
set.seed(123)
12+
expect_error(.retry(a(), ntimes = 3L), "A, got a 0")
1213
})
1314

1415
test_that(".sleep_mult works", {
15-
expect_equal(.sleep_mult(), 5L)
16+
expect_equal(.sleep_mult(), 7L)
1617
})

0 commit comments

Comments
 (0)