-
Notifications
You must be signed in to change notification settings - Fork 38.7k
test: Add and use ElapseTime helper #32430
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
base: master
Are you sure you want to change the base?
Conversation
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. Code Coverage & BenchmarksFor details see: https://corecheck.dev/bitcoin/bitcoin/pulls/32430. ReviewsSee the guideline for information on the review process.
If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update. ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
|
🚧 At least one of the CI tasks failed. HintsTry to run the tests locally, according to the documentation. However, a CI failure may still
Leave a comment here, if you need help tracking down a confusing failure. |
fa123d4 to
fae29c5
Compare
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.
Concept ACK - was thinking of something similar when reviewing 41479ed (#32414)
|
Sorry for the force-pushes, but this uncovered pre-existing issues in the fuzz tests that were not using mocktime during init. So I went ahead and fixed those as well in a separate commit. Should be good now, hopefully 😅 |
w0xlt
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.
ACK fae29c5
|
🚧 At least one of the CI tasks failed. HintsTry to run the tests locally, according to the documentation. However, a CI failure may still
Leave a comment here, if you need help tracking down a confusing failure. |
Went ahead and cherry-picked out the fuzz-fixes into #32927. Should be easy to (re-)review that one. |
fad3690 to
fa1dde3
Compare
|
rebased to drop merged commits and included some minimal fixups |
fa55137 to
fafcff1
Compare
fafcff1 to
faaaaac
Compare
l0rinc
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.
Thanks for fixing these, left quite a few comments, hope you'll find them useful
src/test/fuzz/headerssync.cpp
Outdated
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.
👍 for using the built-in min instead.
Could we add it to the commit message that this isn't just a simple refactor (and not just about the return value), but as @hodlinator stated in a different PR where he did the same:
That way we can always proceed instead of just exiting the fuzz target, wasting cycles. Also reduces code complexity.
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.
thx, split up into a new commit
src/test/util/time.h
Outdated
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.
typo in commit message:
no state is leaked between test cases
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.
thx, fixed
src/test/util/time.h
Outdated
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.
nit: the code isn't in exact alignment with the comment - and since we are calling it with 0, maybe something like:
| Assert(d >= 0s); // Steady time can only move forward. | |
| Assert(d >= 0ms); // Steady time cannot move backward. |
(nit2: I know it's the same, but to clarify that we don't just mean that time-jumps cannot be 0.5 seconds, we might want to use 0ms instead)
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.
thx, reworded comment a bit
src/test/util/time.h
Outdated
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.
nit: I understand that it's meant to be symmetric with ElapseSteady, but I don't find the comment helpful as it is.
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.
thx, reworded comment
src/test/denialofservice_tests.cpp
Outdated
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.
any reason for defining the delta so far away from first usage?
| elapse_time(delta); | |
| const auto delta{3 * std::chrono::seconds{m_node.chainman->GetConsensus().nPowTargetSpacing} + 1s}; | |
| elapse_time(delta); |
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.
Just to make review easier, because you agree that the commit is already large in #32430 (comment). Will leave as-is for now.
src/test/fuzz/p2p_handshake.cpp
Outdated
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.
do we still need to keep these constants or is there maybe a cleaner way now?
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.
seems unrelated? But i am happy to review a pull request changing it
src/test/util/time.h
Outdated
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.
nit: we might as well make the constructors explicit
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.
thx, done
src/bench/util_time.cpp
Outdated
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.
faaaaac58a447c4f8da67ff55a35f7e85cda369f is quite big...
And some of the changes are non-trivial, if you can, please consider doing it in multiple commits
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.
It is just 50 lines, so it should be manageable. Anyone is free to review it file-by-file, if they want to split it up, but I am not sure about splitting it up too much?
This is less code and also required for the next commit.
This is a bit more type-safe than a raw i64.
This makes it easier to use mock-time in tests. Also, it resets the global mocktime, so that no state is leaked between test cases. Also, it resets the global steady mock-time for the same reason.
This is required in the next commit.
faaaaac to
fa80e75
Compare
|
Force pushed with some minor doc-changes and small refactoring in |
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.
code review ACK fa80e75
|
🐙 This pull request conflicts with the target branch and needs rebase. |
|
⌛ There hasn't been much activity lately and the patch still needs rebase. What is the status here?
|
Currently mocktime is written to a global, which may leak between sub-tests (albeit some tests try to reset the mocktime on a best-effort basis). Also, when advancing it, one has to keep a counter variable around.
Fix both issues by a new
ElapseTimehelper, which resets the mocktime once it goes out of scope. Also, it has a method to advance the mocktime by a delta.