Open antoine-sachet opened 5 years ago
Tricky... I'm not sure ::: would be allowed on CRAN. We could make it :: but not include it in the package index? 😐
For sure though, it's super useful for testing. For now I'd encourage anyone who needs this to just copy our code.
I believe :::
is allowed in tests.
Oooh, that's perfect then.
If we do this, wait_for_it
should lose the Sys.sleep(0.1)
and instead pass a timeout to run_now
, I think.
For testing in crrri with promises, we used a hold()
function that wait for promises or reject after a timeout (using a timeout()
function.)
It is one approach that helps us cover with tests all the code using promises.
I just mention this here if you have feedback on doing things better or if it could help others for testing with promises.
In some context, it would be useful to be able to block and wait for a promise to be resolved or rejected.
Typically, I want to test with
testthat
some code that acts on futures or promises, so I want to synchronously check that the resolved value is correct. Thefuture
API offers thevalue
method but it is not implemented bypromises
.I see how you solved this with the
extract
function intests/testthat/common.R
. It would be useful to have access to this blockingextract
function from the package, without confusing the end-users who shouldn't use it.How about as a non-exported function such as
promises:::extract_block
orpromises:::value
?Or maybe it would be neater if
testthat
was promise-aware, with e.g.expect_promise_resolved
andexpect_promise_rejected
?