-
Notifications
You must be signed in to change notification settings - Fork 26
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
It should be possibly to give a timeout value to receivedOnce() #100
Comments
Hi @Kreinoee, thank you for this issue report! To fully understand it I need to clarify something first. Is there any real difference between:
...and:
As I see it the second example is just a syntactic sugar for the 2 seconds waiting. So if the tested async code is slower then usual (more then 2 seconds before the http request), both these verifications will fail. |
Its a bit more than syntactic sugar. In case the async code takes more than 2 seconds before it fires the http request, then the two examples will behave identical. In case where the async code only use 15 milliseconds before it fires the http request, then the first example (using wait), will take 2 seconds before it reports the test as successfull, where the second using withinDuration should report success as soon as it has received and verified the http request. It will properly make more sense to use one of the other suggestions as syntaxt (suggestion 2 or 3), as a normal call to receivedOnce() should return immidiatly. In this case it should not return before it has either received the expected call, or the timeout expires. I guess that this information must be given before or directly to the receivedOnce() call. |
Just to avoid potential duoble work on this. I have made an implementation of this, based on suggesten 2. Onces I am done using it in my current project ( for testing it), I will make a pull request. |
…rifying requests. This fixes jadler-mocking#100
…rifying requests. This fixes jadler-mocking#100
This would make jadler a lot more usefull for testing async code. In this test:
instance.startAsync() starts an async task running on another thread, while the main thread returns immidiatly. The async task runs some logic, that ends up doing the expected HTTP request.
But even though the startAsync() method works as it should, the test will fail, as jadler tries to verify before the async task has had enough time to complete.
A current workaround is to add a wait, so that the test ends up looking like this:
But this is not a nice solution. Setting the wait to low, will make the test fail when run under heavy load, and setting it to high will make the test take much more time than needed.
I would instead suggest that it would be possibly to give jadler a duration of time, in where the expected http request is allowed to be performed. The call should return if the http request is received, or throw an exception if the duration runs out.
Some suggestion to how it could look:
1)
The text was updated successfully, but these errors were encountered: