tests/testthat/test-timeout.R

test_that("r with timeout", {
  tic <- Sys.time()
  e <- tryCatch(
    r(function() Sys.sleep(5), timeout = 1),
    error = function(e) e
  )
  tac <- Sys.time()

  expect_true("callr_timeout_error" %in% class(e))
  expect_true(tac - tic < as.difftime(4, units = "secs"))
  gc()
})

Try the callr package in your browser

Any scripts or data that you put into this service are public.

callr documentation built on Nov. 2, 2022, 5:09 p.m.