-
Notifications
You must be signed in to change notification settings - Fork 480
Support quickcheck based property testing #319
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
Conversation
Quickcheck runs multiple tests in one thread, whereas the testing environment expects one test per thread, since the offchain env is `thread_local!`. This commit adds the possibility to have each test run with an explicitly uninitialized env.
Computationally expensive fuzzing tests should have to be run explicitly with `--features ink-fuzz`. These tests must be marked `#[cfg(feature = "ink-fuzz")]`.
1a1820b to
02f6a90
Compare
By adding the ability to reset the offchain environment explicitly.
Codecov Report
@@ Coverage Diff @@
## master #319 +/- ##
=========================================
Coverage ? 64.29%
=========================================
Files ? 70
Lines ? 5252
Branches ? 0
=========================================
Hits ? 3377
Misses ? 1875
Partials ? 0
Continue to review full report at Codecov.
|
|
@Robbepop Thanks for the comments! I implemented it in a bit of a different way now. Could you take another look please? |
Robbepop
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I see how you try to fix the problems with quickcheck running tests multi threaded, however, to me it currently seems that this causes race conditions onto the underlying off-chain environment that has not at all been implemented in a thread safe manner.
To summarize:
quickcheckruns multiple tests in a single thread- The ink! off-chain environment has a single instance per thread which is no problem for normal Cargo-based tests that run each in their own thread.
- The error we see when
quickchecktests are run is that an already initialized off-chain environment is initialized again. - This PR tries to fix this particular error by introducing a laxer initialization scheme for the off-chain environment.
This fix is problematic since then multiple tests are accessing the off-chain environment concurrently for which it has never been designed. Also the tests might override each others off-chain instances which is death to debugging.
I hope I understood this whole thing correctly. Please correct me if I am wrong.
As of now I would not try to dig further with this approach and instead try to force quickcheck to be running in their own thread as Cargo enforces it for its tests. I do not see any other "easy" solution that would not require us to change the entire functionality of the off-chain instance in order to make it concurrent.
If tests run consecutively this should have been fixed in my upcoming PR for |
Codecov Report
@@ Coverage Diff @@
## master #319 +/- ##
==========================================
+ Coverage 86.67% 87.42% +0.75%
==========================================
Files 107 108 +1
Lines 4219 4272 +53
==========================================
+ Hits 3657 3735 +78
+ Misses 562 537 -25
Continue to review full report at Codecov.
|
|
Just updated the PR and it can be reviewed again. I was able to remove the bulk of the original work, which was originally necessary because of the issue with offchain environments not being reset and quickcheck running in single thread mode. This has resolved itself through other changes in the meantime. So this PR now "just" contains some fuzz tests for In order to execute all tests including fuzz tests use |
|
Updated! Execute all fuzz tests via |
Robbepop
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM besides some nits here and there.
Can you provide us with overall results of your fuzz tests?
Have they found bugs? I myself am unexperienced with fuzz testing so would appreciate more information or another review by someone who has more knowledge than I do.
Also have you looked into proptest? -> https://altsysrq.github.io/proptest-book/proptest/vs-quickcheck.html
To be fair the linked article is biased towards proptest but still to me it looks a bit more flexible. We should definitely not use multiple fuzz testers if we ever want to expand on our fuzz testing capabilities. Also note that I hereby do not propose to change this PR into using proptest just for the sake of it. We can still do this in a follow-up.
Co-authored-by: Hero Bird <[email protected]>
I used it heavily while implementing the The fuzz tests were left out of the original
As discussed in DM I have created a follow-up issue to evaluate and migrate to a better fuzzing library (#464). |
|
|
||
| // when | ||
| // 1) insert all | ||
| xs.iter().for_each(|i| { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
still for_each used instead of normal loop
I'm open for other approaches to solve this.
The problem we have with the new env rev 3 is that quickcheck tests don't run, since quickcheck runs multiple tests in one thread whereas our testing environment expects one test per thread (because of
thread_local!).With multiple tests being subsequently run in the same thread by quickcheck we get an
AlreadyInitializedassertion error.