tests/interactive/test-sleep.R

# These tests need to sleep, which extends test time.
tar_test("seconds has the right object", {
  build <- build_init(quote(Sys.sleep(5L)), baseenv())
  out <- build$metrics$seconds
  expect_equal(out, 5, tolerance = 1e-2)
})

tar_test("branches complete even if patterns do not", {
  tar_script({
    list(
      tar_target(x, c(0, 100)),
      tar_target(y, Sys.sleep(x), pattern = map(x))
    )
  })
  tar_make() # Terminate before the second branch finishes.
  out <- tar_progress()
  expect_equal(out$progress[out$name == "x"], "completed")
  expect_equal(out$progress[out$name == "y"], "dispatched")
  expect_equal(out$progress[out$name == "y_bff916f9"], "completed")
  expect_equal(out$progress[out$name == "y_e15e8827"], "dispatched")
  tar_make() # The first branch should skip. Again, terminate early.
  out <- tar_progress()
  out <- out[out$progress != "skipped", ]
  expect_equal(nrow(out), 2)
  expect_equal(out$progress[out$name == "y"], "dispatched")
  expect_equal(out$progress[out$name == "y_e15e8827"], "dispatched")
})

Try the targets package in your browser

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

targets documentation built on Oct. 3, 2024, 1:11 a.m.