rslota / ex_assert_eventually Goto Github PK
View Code? Open in Web Editor NEWLicense: Apache License 2.0
License: Apache License 2.0
Hello,
I'm curious if it's intentional behaviour that condition check inside eventually
triggered at least twice even if the first call of it yields a successful result?
To demonstrate this I tweaked one of your tests:
test "when match is successful from the first try" do
{:ok, mock} =
start_supervised(
{MockOperation, [success_return: :ok, failure_return: :error, fail_times: 0]}
)
returne_value = assert_eventually :ok = MockOperation.do_something(mock), :ok
assert returne_value == :ok
stats = MockOperation.get_stats(mock)
# by default there should be one call each 20ms
assert stats.call_counter == 1
end
This test will fail as call_counter is gonna be equal 2
and not 1
even though the condition was met after the first call of eventually "block".
I looked through the tests and my guess is that you might have thought of scenarios when the state eventually settles and the assertion yields the same results from one point onward. But imagine the scenario when you getting messages from the queue and you are not sure whether the message is ready to be consumed or delay is required. assert_eventually
looks like the right tool for this job, right? Wrong! If it's just one message and it's ready to be consumed by the time of the first call, it's gonna fetch it with the first call and will fail ugly later on even though the condition of assertion was met. This behaviour is unexpected and it took me some time to figure why my test fails as the matcher basically breaks the expectation of how it should behave.
Would it be possible to change that so assert_eventually
would be useful in the scenario I described as well?
Consider this test:
test "hello world" do
eventually assert variable = Module.hello()
assert :world == variable
end
If you compile this on Elixir 1.11+ you get this warning:
Compiling 1 file (.ex)
Generated eventually_variable app
warning: variable "variable" is unused (if the variable is not meant to be used, prefix it with an underscore)
test/eventually_variable_test.exs:8: EventuallyVariableTest."test get meaningful value by using normal assert"/1
..
Finished in 0.05 seconds
1 doctest, 1 test, 0 failures
Randomized with seed 920761
Obviously the variable is used later in the assert, but the compiler doesn't see that.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.