Skip to content

test: fix intermittent wallet_encryption failures on win64 task - #25021

Closed
jonatack wants to merge 3 commits into
bitcoin:masterfrom
jonatack:fix-intermittent-wallet_encryption-test
Closed

jonatack wants to merge 3 commits into
bitcoin:masterfrom
jonatack:fix-intermittent-wallet_encryption-test

Conversation

@jonatack

@jonatack jonatack commented Apr 28, 2022 •

Copy link
Copy Markdown
Member

@jonatack
jonatack force-pushed the fix-intermittent-wallet_encryption-test branch 4 times, most recently from f6cd3e2 to d47f02b Compare April 28, 2022 22:54
@DrahtBot DrahtBot added the Tests label Apr 28, 2022
@mzumsande

Copy link
Copy Markdown
Contributor

Strange that this happens twice in a day suddenly, without any recent changes that look related. The linked CI runs fail at different subtests, one at ("Check a timeout less than the limit") and one at ("Check a timeout greater than the limit") - so a fix should probably also affect both.

@maflcko

maflcko commented Apr 29, 2022

Copy link
Copy Markdown
Member

I can't see how this would happen unless the python clock is ahead of the system clock??

@jonatack
jonatack force-pushed the fix-intermittent-wallet_encryption-test branch from d47f02b to f446ea6 Compare April 29, 2022 12:24
@jonatack

jonatack commented Apr 29, 2022 •

Copy link
Copy Markdown
Member Author

Yeah, it's weird. Win64-only so far. Let's see if there are more failures.

Thanks @mzumsande, re-pushed with a smaller additional margin for both tests.

@jonatack
jonatack force-pushed the fix-intermittent-wallet_encryption-test branch from f446ea6 to aa26dfd Compare April 29, 2022 12:29
@jonatack

Copy link
Copy Markdown
Member Author

Another one: https://cirrus-ci.com/task/4631236957175808

  File "C:\Users\ContainerAdministrator\AppData\Local\Temp\cirrus-ci-build\test\functional\wallet_encryption.py", line 93, in run_test
    assert_greater_than(expected_time_with_buffer, actual_time)
  File "C:\Users\ContainerAdministrator\AppData\Local\Temp\cirrus-ci-build\test\functional\test_framework\util.py", line 56, in assert_greater_than
    raise AssertionError("%s <= %s" % (str(thing1), str(thing2)))

AssertionError: 1751237054.993892 <= 1751237055

@jonatack jonatack changed the title test: fix intermittent wallet_encryption functional test test: fix intermittent wallet_encryption failures on win64 task Apr 29, 2022
@bitcoin bitcoin deleted a comment Apr 29, 2022
@bitcoin bitcoin deleted a comment Apr 29, 2022
@jonatack

jonatack commented May 3, 2022

Copy link
Copy Markdown
Member Author

@vasild

vasild commented May 6, 2022

Copy link
Copy Markdown
Contributor

I think a possible explanation would be if the GetTime() in the C++ code on Windows ends up rounding up to a whole second. So, for example:

  1. expected time = int(10.5) + MAX = 10 + MAX
  2. 0.1 second passes
  3. walletpassphrase RPC is executed, asking it to keep the phrase for MAX seconds, it calculates now=ceil(10.6) + MAX = 11 + MAX // ceil() wtf!?
  4. 0.1 second passes
  5. expected with buffer = 10.7 + MAX // not truncated to whole seconds

So, we end up with actual time (11 + MAX) < expected with buffer (10.7 + MAX).

If this guess is correct, then the following should fix it:

before = math.floor(time.time()) + MAX_VALUE
self.nodes[0].walletpassphrase(passphrase2, MAX_VALUE + 1000) 
after = math.ceil(time.time()) + MAX_VALUE 
actual = self.nodes[0].getwalletinfo()['unlocked_until'] 
assert_greater_than_or_equal(actual, before)
assert_greater_than_or_equal(after, actual)

@jonatack
jonatack force-pushed the fix-intermittent-wallet_encryption-test branch from aa26dfd to 76f8dc9 Compare May 10, 2022 11:51
@jonatack

jonatack commented May 10, 2022 •

Copy link
Copy Markdown
Member Author

@vasild done (thanks for looking into this) and added a commit for test logging (and named args and an assertion).

@vasild vasild left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 76f8dc9bd1b4efd543dc54c17a5f8e9d512580e1

Comment thread test/functional/wallet_encryption.py Resolved
@jonatack
jonatack force-pushed the fix-intermittent-wallet_encryption-test branch from 76f8dc9 to 1a82609 Compare May 12, 2022 15:12
@maflcko

maflcko commented May 12, 2022

Copy link
Copy Markdown
Member

Is this still an issue? I haven't seen it recently.

@jonatack

Copy link
Copy Markdown
Member Author

Haven't seen it in a week. Could drop the fix for now and leave the improvements.

@ryanofsky

Copy link
Copy Markdown
Contributor

Just saw this error: https://cirrus-ci.com/task/4948737314258944?logs=functional_tests#L25 in #24230

Log:

 node0 2022-05-12T20:03:02.859261Z [C:\Users\ContainerAdministrator\AppData\Local\Temp\cirrus-ci-build\src\rpc\request.cpp:179] [parse] ThreadRPCServer method=walletpassphrase user=__cookie__ 
 node0 2022-05-12T20:03:03.012258Z [C:\Users\ContainerAdministrator\AppData\Local\Temp\cirrus-ci-build\src\rpc\server.cpp:530] [RPCRunLater] queue run of timer lockwallet(default_wallet) in 99999400 seconds (using HTTP) 
 test  2022-05-12T20:03:03.014000Z TestFramework (ERROR): Assertion failed 
                                   Traceback (most recent call last):
                                     File "C:\Users\ContainerAdministrator\AppData\Local\Temp\cirrus-ci-build\test\functional\test_framework\test_framework.py", line 133, in main
                                       self.run_test()
                                     File "C:\Users\ContainerAdministrator\AppData\Local\Temp\cirrus-ci-build\test\functional\wallet_encryption.py", line 85, in run_test
                                       assert_greater_than(expected_time_with_buffer, actual_time)
                                     File "C:\Users\ContainerAdministrator\AppData\Local\Temp\cirrus-ci-build\test\functional\test_framework\util.py", line 56, in assert_greater_than
                                       raise AssertionError("%s <= %s" % (str(thing1), str(thing2)))
                                   AssertionError: 1752385182.999136 <= 1752385183

@maflcko

maflcko commented May 13, 2022

Copy link
Copy Markdown
Member

Ok, then I think we should only maim the test on windows, not on all platforms.

@vasild vasild left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 1a82609ce078e2d3e5e242d85b275b950fd6fb8f

Why "maim"? The test functionality if fully preserved, no?

cc @achow101, author of these tests

@maflcko

maflcko commented May 13, 2022

Copy link
Copy Markdown
Member

Why "maim"? The test functionality if fully preserved, no?

Sure, "maim" is a bit too strong. It is making the test lax by up to another second, while no one understands why.

@maflcko

maflcko commented May 13, 2022

Copy link
Copy Markdown
Member

Would be nice if someone could run this on msvc:

#include <iostream>
#include <chrono>
#include <string>
 
template <typename TimePoint>
std::string to_string(const TimePoint& time_point)
{
    return std::to_string(time_point.time_since_epoch().count());
}
 
int main()
{
    using namespace std::literals::chrono_literals;
    using Sec = std::chrono::seconds;
 
    std::cout << "Time point\t" "Cast\t" "Floor\t" "Round\t" "Ceil\n";
    std::cout << "(ms)\t\t"     "(s)\t"  "(s)\t"   "(s)\t"   "(s)\n";
    for (const auto value_ms: {5432ms, 5678ms}) {
        std::chrono::time_point<std::chrono::system_clock, std::chrono::milliseconds>
            time_point_ms(value_ms);
 
        std::cout
            << to_string(time_point_ms) << "\t\t"
            << to_string(std::chrono::time_point_cast<Sec>(time_point_ms)) << "\t"
            << to_string(std::chrono::floor          <Sec>(time_point_ms)) << "\t"
            << to_string(std::chrono::round          <Sec>(time_point_ms)) << "\t"
            << to_string(std::chrono::ceil           <Sec>(time_point_ms)) << "\n";
    }
}

From https://en.cppreference.com/w/cpp/chrono/time_point/ceil. Should print:

Time point	Cast	Floor	Round	Ceil
(ms)		(s)	(s)	(s)	(s)
5432		5	5	5	6
5678		5	5	6	6

@vasild

vasild commented May 13, 2022

Copy link
Copy Markdown
Contributor

It is making the test lax by up to another second

That is true, but the point of the test is to ensure that the time limit is honored - 1. cannot be negative, 2. is capped at some limit and 3. if within the limits, then is accepted. The original test in 134cdc7 contained 5 seconds buffer, so the point of the test is not to check that the value is accepted up to the second, exactly.

Comment thread test/functional/wallet_encryption.py Resolved
@maflcko

maflcko commented Jul 25, 2022

Copy link
Copy Markdown
Member

I haven't seen it yet, so it indeed seems like a bug in Windows 2019

@jonatack

Copy link
Copy Markdown
Member Author

@jonatack

Copy link
Copy Markdown
Member Author

@vasild

vasild commented Jul 29, 2022

Copy link
Copy Markdown
Contributor

@jonatack

Copy link
Copy Markdown
Member Author

@jonatack

Copy link
Copy Markdown
Member Author

Seems this won't be merged.

@jonatack jonatack closed this Jul 30, 2022
@maflcko

maflcko commented Jul 30, 2022

Copy link
Copy Markdown
Member

The reason I haven't merged this yet is that it has only one ACK, but outstanding review comments such as #25021 (comment) and #25021 (comment)

Also, I am not sure if a test fix should modify the cpp source code. No objection to those changes, but maybe try to submit them separate from a test fix?

@vasild

vasild commented Aug 10, 2022

Copy link
Copy Markdown
Contributor

The reason for closing - "this won't be merged" seems unjustified to me. If Marco did not merge it in the past, that does not mean he will not merge it in the future. Or that another maintainer will not merge it in the future.

Indeed it has just one ACK. @achow101, maybe you can review this, since you are the original author of the tests.

I think this PR should be reopened, IMO it is an improvement even if it does not fix the mysterious test failures.

@maflcko

maflcko commented Aug 10, 2022

Copy link
Copy Markdown
Member

For reference, I created #25750 two weeks ago

@jonatack

jonatack commented Aug 10, 2022 •

Copy link
Copy Markdown
Member Author

I think this PR should be reopened, IMO it is an improvement even if it does not fix the mysterious test failures.

Ok, re-opening.

Note also that many test changes (and regular codebase ones, #25656 would be an example merged today) are merged with one ACK, so this doesn't seem to be a hard rule.

@jonatack jonatack reopened this Aug 10, 2022
@jonatack

jonatack commented Aug 10, 2022 •

Copy link
Copy Markdown
Member Author

For reference, I created #25750 two weeks ago

I'm happy to update this PR with suggestions for improvements or a different approach.

jonatack and others added 3 commits August 10, 2022 16:58
note: using std::min here shouldn't add to the compilation time of
src/wallet/rpc/encrypt.cpp, as src/wallet/wallet.h that it
depends on already includes the algorithm library.

Also added this file to the clang-tidy include-what-you-use CI script
and updated the headers.
@jonatack
jonatack force-pushed the fix-intermittent-wallet_encryption-test branch from 1a82609 to 189f57b Compare August 10, 2022 15:03
@jonatack

Copy link
Copy Markdown
Member Author

Updated to improve assertion error, changed the first commit message from "fix" to "work around" and rebased to current master to enable clang-tidy iwyu checks on the second commit (will re-push after the clang-tidy CI run). Happy to split out the some of changes to a separate pull or to update the approach if reviewers prefer.

@fanquake

Copy link
Copy Markdown
Member

https://github.com/bitcoin/bitcoin/pull/25021/files#r873198183

Has this been is addressed? If yes, can you mark it as resolved, if not, can you comment?

changed the first commit message from "fix" to "work around"

If this is now a work around, rather than a fix, I'd rather use the work-around that is contained to the platform that is broken, i.e #25750, rather than refactoring code that works for all other platforms, and essentially hiding the bug on Windows. At least until we properly understand the issue; see debugging in #25482.

The PR title and description need updating in any case.

@maflcko

maflcko commented Aug 10, 2022

Copy link
Copy Markdown
Member

Can you explain why the workaround here is better than the one in #25750?

@jonatack

Copy link
Copy Markdown
Member Author

Can you explain why the workaround here is better than the one in #25750?

I'm happy to update this PR with suggestions for improvements or a different approach.

ATM am looking into the discussion in #25482.

@DrahtBot

DrahtBot commented Aug 11, 2022 •

Copy link
Copy Markdown
Contributor

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #25878 (tests: Use mocktime for wallet encryption timeout by achow101)
  • #25750 (test: Temporarily work around Windows bug in walletpassphrase by MarcoFalke)

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.

@achow101

Copy link
Copy Markdown
Member

It seems like instead of messing around with buffers and relaxing ranges, this could just be resolved through the use of mock time so that bitcoind is set to a fixed time.

@jonatack

Copy link
Copy Markdown
Member Author

I'll give that a shot 👍

@maflcko

maflcko commented Aug 18, 2022

Copy link
Copy Markdown
Member

For reference, I suggested mocktime in May: #25021 (comment)

This should be fine to do here, as the time returned has no guarantee to be related to the real relock time, which happens completely independent in the libevent scheduler thread.

@jonatack jonatack closed this Aug 20, 2022
@bitcoin bitcoin locked and limited conversation to collaborators Aug 20, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants