-
Notifications
You must be signed in to change notification settings - Fork 37.7k
Util: Allow scheduler to be mocked #18037
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
Some relevant info about the analysis of the cost (maintenance burden) vs benefit (supporting a better tested & simpler codebase) of these changes pros:
cons:
explanation of the two use cases & workarounds.
|
utACK 58c4c19. This seems like a generally useful test harness, and the code looks basically correct to me. I think the pointer to the scheduler is a little crass, but it isn't a bad option considering the scheduler is created as a static in init.cpp (someone can clean it up later if they make the schedule a non static). The time delta technically could underflow, but I don't think that's the base time being subtracted from is a time point (and we're far from the unix epoch time). If this weren't just testing harness, it might be worth it to check for underflow, but since we'd basically be having to actively try to shoot ourselves in the foot during a test to get an underflow this usage is fine. Great work! |
Concept ACK. Looks like there's an issue with the new test/scheduler_tests.cpp(158): Entering test case "mockforward"
test/scheduler_tests.cpp(188): error: in "scheduler_tests/mockforward": check num_tasks == 1 has failed [3 != 1]
test/scheduler_tests.cpp(191): error: in "scheduler_tests/mockforward": check counter == 2 has failed [0 != 2]
test/scheduler_tests.cpp(197): error: in "scheduler_tests/mockforward": check delta > 2*60 && delta < 3*60 has failed
test/scheduler_tests.cpp(158): Leaving test case "mockforward"; testing time: 6321us
test/scheduler_tests.cpp(13): Leaving test suite "scheduler_tests"; testing time: 146946us |
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. 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. |
No objection, but some observations:
So my personal preference would be to go with some minimally invasive and simple approach like the chainparam. But if everyone else likes this mock approach because it could be used for other testing needs as well, then I won't object having this merged. |
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.
Some minor comments otherwise change LGTM.
88bc0fd
to
ecb0ad5
Compare
I addressed review comments & tests are now passing CI. Added checks in RPC function & scheduler function to ensure reasonable values / no underflow. This PR has received 3 ACKs - utACK from @JeremyRubin & concept ACKs from @promag @fanquake. Would appreciate re-review 🙏🏽 |
re-utACK ecb0ad5 |
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.
@amitiuttarwar sure, will review later.
@@ -570,6 +600,7 @@ static const CRPCCommand commands[] = | |||
|
|||
/* Not shown in help */ | |||
{ "hidden", "setmocktime", &setmocktime, {"timestamp"}}, | |||
{ "hidden", "mockscheduler", &mockscheduler, {"delta_time"}}, |
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.
Follow up, would be cool to skip this when !regtest and in mockscheduler
would be assert(Params().MineBlocksOnDemand())
.
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 it's reasonable for @amitiuttarwar to just copy exactly what setmocktime is doing in this regard.
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.
Huh? static const commands[]=
will get done prior to working out what chain is in use, so you'd have to do a much more serious rework to remove it from the list of rpcs entirely.
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's a hidden RPC so I don't think this matters much.
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.
@ajtowns I was thinking that CRPCTable::execute
could take into account some CRPCCommand
flag and then it would result in RPC_METHOD_NOT_FOUND
.
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.
FWIW there's no coverage for mockscheduler
RPC, just a simple call in the test framework would be nice.
@promag I think it's reasonable that the mockscheduler RPC doesn't have coverage presently -- @amitiuttarwar has a larger project that this testing harness was extracted from as a reviewable chunk, a later PR will be using it extensively to test rebroadcasting logic (see #18038). I think it's reasonable that the coverage in RPC tests lives there & there isn't a separate one just testing the testing rpc, but feel free to disagree. |
thanks for review @promag! RE testing mockscheduler RPC- as @JeremyRubin mentioned, my next PR uses it here , so the happy path will be tested. But if you prefer separate explicit test coverage, I can add. I'll incorporate style nits if I push & invalidate current ACKs |
@@ -570,6 +600,7 @@ static const CRPCCommand commands[] = | |||
|
|||
/* Not shown in help */ | |||
{ "hidden", "setmocktime", &setmocktime, {"timestamp"}}, | |||
{ "hidden", "mockscheduler", &mockscheduler, {"delta_time"}}, |
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's a hidden RPC so I don't think this matters much.
ecb0ad5
to
cf04e02
Compare
changes:
other comments:
So I believe all existing review comments are addressed. This PR is ready for review :) |
s390x travis build is failing with "Disk space is too low!" error. everything else is green appveyor |
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 cf04e02 only some style nits 🔵
Show signature and timestamp
Signature:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512
ACK cf04e02bbe14257a1513b029231cb6a21c9766ac only some style nits 🔵
-----BEGIN PGP SIGNATURE-----
iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
pUgrVAwAzQPXXwQxaHhiRYtQO0W21qQLUyCF92Bvjtq2RMMQnmkrQZ8sIeyFkka9
Mm0FDE2e0eU4en2Xw4CK/7yFsWUxlOMx8vrOlzYttO9htkmVT95Rnm7HOuAShvav
lcuEloyfjMe0bKAR+X/X51/roJhf+WSGrKsEFI8C+FV/bu/AbOOxlLEFiW9v6Wo3
83aqh74lXb5B3Bf4aZJRSTAJhlUE9XNlMH664laqefks2HXyseZpvomRd/w90NX/
VC9UzgeTUnSqUAGd278nFFAf1J5tqIfnE37USY1EokaZw4Yc8zsdYOYHUK1ZklEw
ZHIF3WPRln9OaR7kLfWtHslQUnCo1797qP2ouWAVpgRVXl63cNmjMqRGJErGZtXK
23bKPE3D1CgEdb+dO422dKlbiI4Nsdg0pkwnAR/z+KLBwCu+oov2KF3kPhwVdQfq
pUNQMn/cS7X9QP7bHxQOlAnpl4ijuBJfbV+wqU+0fY/WfclKyM/20u7IFecoZFOz
CYu4fn+Z
=NQgO
-----END PGP SIGNATURE-----
Timestamp of file with hash 6c8ec4d2d3fd87097e17c0ce53d45761554026de152c054c527f36f2fdc7f39b -
Thank you for the review @MarcoFalke ! I addressed your concerns in a commit (with one open question), currently opened as a PR on my fork: amitiuttarwar#2, will make as a follow up PR if this one gets accepted. Tried to investigate the appveyor failure and cannot see how it could possibly be related to my changes. |
ACK 8bca30e, only change is some style fixups 🕓 Show signature and timestampSignature:
Timestamp of file with hash |
8bca30e [rpc] expose ability to mock scheduler via the rpc (Amiti Uttarwar) 7c8b6e5 [lib] add scheduler to node context (Amiti Uttarwar) 930d837 [test] add chainparams property to indicate chain allows time mocking (Amiti Uttarwar) 1cd43e8 [test] unit test for new MockForward scheduler method (Amiti Uttarwar) a6f6359 [util] allow scheduler to be mocked (Amiti Uttarwar) Pull request description: This PR is to support functional tests by allowing the scheduler to be mocked via the RPC. It adds a `MockForward` method to the scheduler class that iterates through the task queue and reschedules them to be `delta_seconds` sooner. This is currently used to support functional testing of the "unbroadcast" set tracking in #18038. If this patch is accepted, it would also be useful to simplify the code in #16698. ACKs for top commit: MarcoFalke: ACK 8bca30e, only change is some style fixups 🕓 Tree-SHA512: 2a97fe8ade2b7fd1fb5cdfa1dcafb3227a377d7a847e3845a228bc119eb77824b4aefa43d922a06d583939b22725e223f308cf092961048079d36f6b1d9a639b
8bca30e [rpc] expose ability to mock scheduler via the rpc (Amiti Uttarwar) 7c8b6e5 [lib] add scheduler to node context (Amiti Uttarwar) 930d837 [test] add chainparams property to indicate chain allows time mocking (Amiti Uttarwar) 1cd43e8 [test] unit test for new MockForward scheduler method (Amiti Uttarwar) a6f6359 [util] allow scheduler to be mocked (Amiti Uttarwar) Pull request description: This PR is to support functional tests by allowing the scheduler to be mocked via the RPC. It adds a `MockForward` method to the scheduler class that iterates through the task queue and reschedules them to be `delta_seconds` sooner. This is currently used to support functional testing of the "unbroadcast" set tracking in bitcoin#18038. If this patch is accepted, it would also be useful to simplify the code in bitcoin#16698. ACKs for top commit: MarcoFalke: ACK 8bca30e, only change is some style fixups 🕓 Tree-SHA512: 2a97fe8ade2b7fd1fb5cdfa1dcafb3227a377d7a847e3845a228bc119eb77824b4aefa43d922a06d583939b22725e223f308cf092961048079d36f6b1d9a639b
This PR seems to have made bitcoinbuilds.org pretty unhappy:
Example build: Any ideas why we see a SIGABRT? I think it happens at |
@jonasschnelli See #18174 |
@MarcoFalke: I guess you where trying to refer to #18174. Looking into that now... |
Master ( Master succeeds when clearing the ccache cache (but keeping the dependency cache): |
…hain 2455aa5 [rpc] changed MineBlocksOnDemand to IsMockableChain (Gloria Zhao) Pull request description: Change: Update the if statement in `setmocktime` to use `IsMockableChain` chainparams function (aka `m_is_mockable_chain`) instead of `MineBlocksOnDemand` Rationale: It's a more appropriate check for whether or not chain is in RegTest, as [discussed](bitcoin#18037 (comment)) in bitcoin#18037 ACKs for top commit: MarcoFalke: ACK 2455aa5 🙇 jonatack: ACK 2455aa5 Tree-SHA512: 1d8c8b7ff0b3c1bcbf5755194969b6664fe05a35003375ad08d18e34bcefd2df4f64d0e60078a10bbef3c8f469a9b9d07db467089b55c14cf532304bc965bffc
Summary: Add MockForward method to the scheduler that mimics going into the future by rescheduling all items on the taskQueue to be sooner. This is a partial backport of Core [[bitcoin/bitcoin#18037 | PR18037]] : bitcoin/bitcoin@a6f6359 Test Plan: ninja all check-all Reviewers: #bitcoin_abc, majcosta Reviewed By: #bitcoin_abc, majcosta Differential Revision: https://reviews.bitcoinabc.org/D6499
Summary: This is a partial backport of Core [[bitcoin/bitcoin#18037 | PR18037]] : bitcoin/bitcoin@1cd43e8 Depends on D6499 Test Plan: ninja all check-all Reviewers: #bitcoin_abc, majcosta Reviewed By: #bitcoin_abc, majcosta Differential Revision: https://reviews.bitcoinabc.org/D6500
Summary: Thi is a partial backport of Core [[bitcoin/bitcoin#18037 | PR18037]] : bitcoin/bitcoin@930d837 Depends on D6500 Test Plan: ninja all check-all Reviewers: #bitcoin_abc, majcosta Reviewed By: #bitcoin_abc, majcosta Differential Revision: https://reviews.bitcoinabc.org/D6501
Summary: - also update test setup & access point in denial of service test This is a partial backport of Core [[bitcoin/bitcoin#18037 | PR18037]] : bitcoin/bitcoin@7c8b6e5 Depends on D6501 Test Plan: ninja all check-all Reviewers: #bitcoin_abc, majcosta Reviewed By: #bitcoin_abc, majcosta Differential Revision: https://reviews.bitcoinabc.org/D6502
Summary: This is a partial abckport of Core [[bitcoin/bitcoin#18037 | PR18037]] : bitcoin/bitcoin@8bca30e Depends on D6502 and D6498 Test Plan: ninja all check-all Reviewers: #bitcoin_abc, majcosta Reviewed By: #bitcoin_abc, majcosta Differential Revision: https://reviews.bitcoinabc.org/D6503
Summary: Add MockForward method to the scheduler that mimics going into the future by rescheduling all items on the taskQueue to be sooner. This is a partial backport of Core [[bitcoin/bitcoin#18037 | PR18037]] : bitcoin/bitcoin@a6f6359 Test Plan: ninja all check-all Reviewers: #bitcoin_abc, majcosta Reviewed By: #bitcoin_abc, majcosta Differential Revision: https://reviews.bitcoinabc.org/D6499
Summary: This is a partial backport of Core [[bitcoin/bitcoin#18037 | PR18037]] : bitcoin/bitcoin@1cd43e8 Depends on D6499 Test Plan: ninja all check-all Reviewers: #bitcoin_abc, majcosta Reviewed By: #bitcoin_abc, majcosta Differential Revision: https://reviews.bitcoinabc.org/D6500
8bca30e [rpc] expose ability to mock scheduler via the rpc (Amiti Uttarwar) 7c8b6e5 [lib] add scheduler to node context (Amiti Uttarwar) 930d837 [test] add chainparams property to indicate chain allows time mocking (Amiti Uttarwar) 1cd43e8 [test] unit test for new MockForward scheduler method (Amiti Uttarwar) a6f6359 [util] allow scheduler to be mocked (Amiti Uttarwar) Pull request description: This PR is to support functional tests by allowing the scheduler to be mocked via the RPC. It adds a `MockForward` method to the scheduler class that iterates through the task queue and reschedules them to be `delta_seconds` sooner. This is currently used to support functional testing of the "unbroadcast" set tracking in bitcoin#18038. If this patch is accepted, it would also be useful to simplify the code in bitcoin#16698. ACKs for top commit: MarcoFalke: ACK 8bca30e, only change is some style fixups 🕓 Tree-SHA512: 2a97fe8ade2b7fd1fb5cdfa1dcafb3227a377d7a847e3845a228bc119eb77824b4aefa43d922a06d583939b22725e223f308cf092961048079d36f6b1d9a639b
Summary: > Change: Update the if statement in setmocktime to use IsMockableChain chainparams function (aka m_is_mockable_chain) instead of MineBlocksOnDemand > > Rationale: It's a more appropriate check for whether or not chain is in RegTest, as discussed in [[bitcoin/bitcoin#18037 | PR18037]] This is a backport of Core [[bitcoin/bitcoin#18263 | PR18263]] Test Plan: `ninja all check-all` Reviewers: #bitcoin_abc, Fabien Reviewed By: #bitcoin_abc, Fabien Differential Revision: https://reviews.bitcoinabc.org/D8783
…hain 2455aa5 [rpc] changed MineBlocksOnDemand to IsMockableChain (Gloria Zhao) Pull request description: Change: Update the if statement in `setmocktime` to use `IsMockableChain` chainparams function (aka `m_is_mockable_chain`) instead of `MineBlocksOnDemand` Rationale: It's a more appropriate check for whether or not chain is in RegTest, as [discussed](bitcoin#18037 (comment)) in bitcoin#18037 ACKs for top commit: MarcoFalke: ACK 2455aa5 🙇 jonatack: ACK 2455aa5 Tree-SHA512: 1d8c8b7ff0b3c1bcbf5755194969b6664fe05a35003375ad08d18e34bcefd2df4f64d0e60078a10bbef3c8f469a9b9d07db467089b55c14cf532304bc965bffc
…hain 2455aa5 [rpc] changed MineBlocksOnDemand to IsMockableChain (Gloria Zhao) Pull request description: Change: Update the if statement in `setmocktime` to use `IsMockableChain` chainparams function (aka `m_is_mockable_chain`) instead of `MineBlocksOnDemand` Rationale: It's a more appropriate check for whether or not chain is in RegTest, as [discussed](bitcoin#18037 (comment)) in bitcoin#18037 ACKs for top commit: MarcoFalke: ACK 2455aa5 🙇 jonatack: ACK 2455aa5 Tree-SHA512: 1d8c8b7ff0b3c1bcbf5755194969b6664fe05a35003375ad08d18e34bcefd2df4f64d0e60078a10bbef3c8f469a9b9d07db467089b55c14cf532304bc965bffc
…hain 2455aa5 [rpc] changed MineBlocksOnDemand to IsMockableChain (Gloria Zhao) Pull request description: Change: Update the if statement in `setmocktime` to use `IsMockableChain` chainparams function (aka `m_is_mockable_chain`) instead of `MineBlocksOnDemand` Rationale: It's a more appropriate check for whether or not chain is in RegTest, as [discussed](bitcoin#18037 (comment)) in bitcoin#18037 ACKs for top commit: MarcoFalke: ACK 2455aa5 🙇 jonatack: ACK 2455aa5 Tree-SHA512: 1d8c8b7ff0b3c1bcbf5755194969b6664fe05a35003375ad08d18e34bcefd2df4f64d0e60078a10bbef3c8f469a9b9d07db467089b55c14cf532304bc965bffc
This PR is to support functional tests by allowing the scheduler to be mocked via the RPC.
It adds a
MockForward
method to the scheduler class that iterates through the task queue and reschedules them to bedelta_seconds
sooner.This is currently used to support functional testing of the "unbroadcast" set tracking in #18038. If this patch is accepted, it would also be useful to simplify the code in #16698.