Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide a way to block and wait for a promise (for testing) #48

Open
antoine-sachet opened this issue May 30, 2019 · 5 comments
Open

Provide a way to block and wait for a promise (for testing) #48

antoine-sachet opened this issue May 30, 2019 · 5 comments

Comments

@antoine-sachet
Copy link

antoine-sachet commented May 30, 2019

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. The future API offers the value method but it is not implemented by promises.

I see how you solved this with the extract function in tests/testthat/common.R. It would be useful to have access to this blocking extract 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 or promises:::value?

Or maybe it would be neater if testthat was promise-aware, with e.g. expect_promise_resolved and expect_promise_rejected?

@antoine-sachet antoine-sachet changed the title Provide a way to block and wait for a future (for testing) Provide a way to block and wait for a promise (for testing) May 30, 2019
@jcheng5
Copy link
Member

jcheng5 commented Aug 13, 2019

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.

@wch
Copy link
Collaborator

wch commented Aug 13, 2019

I believe ::: is allowed in tests.

@jcheng5
Copy link
Member

jcheng5 commented Aug 13, 2019

Oooh, that's perfect then.

@jcheng5
Copy link
Member

jcheng5 commented Aug 13, 2019

If we do this, wait_for_it should lose the Sys.sleep(0.1) and instead pass a timeout to run_now, I think.

@cderv
Copy link
Contributor

cderv commented Aug 15, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants