From 41d70a94a7d7c74e00605417869610e16ba45ba1 Mon Sep 17 00:00:00 2001 From: Hadley Wickham Date: Thu, 24 Oct 2024 11:36:01 -0500 Subject: [PATCH] Fix flaky cache test Fixes #570 --- tests/testthat/test-req-perform.R | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/testthat/test-req-perform.R b/tests/testthat/test-req-perform.R index 7cc147c2..0dbafcc5 100644 --- a/tests/testthat/test-req-perform.R +++ b/tests/testthat/test-req-perform.R @@ -115,7 +115,7 @@ test_that("can cache requests with etags", { test_that("can cache requests with paths (cache-control)", { req <- request(example_url()) %>% - req_url_path("/cache/1") %>% + req_url_path("/cache/2") %>% req_cache(withr::local_tempfile()) path1 <- withr::local_tempfile() @@ -132,7 +132,11 @@ test_that("can cache requests with paths (cache-control)", { ) expect_equal(resp2$body[[1]], path2) - Sys.sleep(1.1) # wait for cache to expire + # Wait until cache expires + cached_resp <- cache_get(req) + info <- resp_cache_info(cached_resp) + Sys.sleep(max(as.double(info$expires - Sys.time()), 0)) + path3 <- withr::local_tempfile() expect_condition( resp3 <- req %>% req_perform(path = path3),