Debian Codegraph @

tests/testthat/test-promise-domains.R

raw
1 with_several_promise_domains <- function(expr) {
2 withReactiveDomain(MockShinySession$new(), {
3 with_promise_domain(reactivePromiseDomain(), {
4 captureStackTraces({
5 expr
6 })
7 })
8 })
9 }
10
11 recursive_promise <- function(n, callback = identity) {
12 if (n <= 0) {
13 return(promise_resolve(0))
14 }
15
16 p <- promises::promise_resolve(TRUE)
17 promises::then(p, ~{
18 callback(n)
19 recursive_promise(n - 1, callback = callback)
20 })
21 }
22
23 test_that("Stack trace doesn't grow (resolution within domain)", {
24
25 depths <- list()
26 with_several_promise_domains({
27 recursive_promise(10, function(n) {
28 depths <<- c(depths, list(length(sys.calls())))
29 })
30 while (!later::loop_empty()) {
31 later::run_now()
32 }
33 })
34 expect_equal(diff(range(depths)), 0)
35 })
36
37 test_that("Stack trace doesn't grow (resolution outside domain)", {
38
39 depths <- list()
40 with_several_promise_domains({
41 recursive_promise(10, function(n) {
42 depths <<- c(depths, list(length(sys.calls())))
43 })
44 })
45 while (!later::loop_empty()) {
46 later::run_now()
47 }
48 expect_equal(diff(range(depths)), 0)
49 })