Skip to content

[mini.test] testing async functions #1107

Closed Answered by echasnovski
maxandron asked this question in Q&A
Discussion options

You must be logged in to vote

This very much depends on the tested function.

If the problem here is to test a function which executes not immediately and can take unknown beforehand amount of time to finish, then the most straightforward approach is to wait some amount of time before checking the state of the child process. This is how I usually go with it. Here is an example from 'mini.test' test. Choosing an actual time to wait is tricky: should be long enough to have small number of false negatives but not long enough to unnecessarily prolong test execution.

The other situation is if async function is meant to do something in a known amount of time (like show completion in 300 ms). Then the approach is similar but …

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@maxandron
Comment options

@echasnovski
Comment options

@maxandron
Comment options

Answer selected by echasnovski
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
2 participants