Skip to content

test: Add random interval upper bound in regtest - #19588

Closed
hebasto wants to merge 1 commit into
bitcoin:masterfrom
hebasto:200725-uni-test
Closed

hebasto wants to merge 1 commit into
bitcoin:masterfrom
hebasto:200725-uni-test

Conversation

@hebasto

@hebasto hebasto commented Jul 25, 2020

Copy link
Copy Markdown
Member

Actually, the exponential distribution is unbounded that causes intermittent timeout errors in functional tests.

Fix #18832
Fix #18969
Fix #19265
Fix #19311

Comment thread src/init.cpp Outdated
gArgs.AddArg("-rpcwhitelistdefault", "Sets default behavior for rpc whitelisting. Unless rpcwhitelistdefault is set to 0, if any -rpcwhitelist is set, the rpc server acts as if all rpc users are subject to empty-unless-otherwise-specified whitelists. If rpcwhitelistdefault is set to 1 and no -rpcwhitelist is set, rpc server acts as if all rpc users are subject to empty whitelists.", ArgsManager::ALLOW_BOOL, OptionsCategory::RPC);
gArgs.AddArg("-rpcworkqueue=<n>", strprintf("Set the depth of the work queue to service RPC calls (default: %d)", DEFAULT_HTTP_WORKQUEUE), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::RPC);
gArgs.AddArg("-server", "Accept command line and JSON-RPC commands", ArgsManager::ALLOW_ANY, OptionsCategory::RPC);
gArgs.AddArg("-uniformintervaltest", "Use uniform distribution for random intervals instead of exponential one (default: 0)", ArgsManager::ALLOW_BOOL | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

not sure if adding another mock-setting is the right approach here

  • This is not guarded and can accidentally be set on mainnet
  • This will run a different code path when set (partially code that has been added for this test-setting only), thus reducing the effectiveness of tests and increasing the maintenance burden
  • There is already a way to mock the poisson dist with the noban permission (This could be extracted to a hidden test-only permission if there are concerns about noban being too broad)
  • A timeout of 60s with the expected value of the poisson dist (5s or 7s or whatever) yields a failure rate that is far lower than the failure rate we see due to infrastructure problems or other test problems and races. The issue here is that the nodes are daisy chained and thus the delays add up, which could bring the delay over 60s more likely.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

  • This is not guarded and can accidentally be set on mainnet

Yes. It must be guarded. Going to fix it.

  • This will run a different code path when set (partially code that has been added for this test-setting only), thus reducing the effectiveness of tests and increasing the maintenance burden

The current code path, which is skipped in tests with this PR, is not covered by tests in master.

  • There is already a way to mock the poisson dist with the noban permission (This could be extracted to a hidden test-only permission if there are concerns about noban being too broad)

This approach does not work universally, e.g., in wallet_backup.py:

self.extra_args = [
["[email protected]", "-keypool=100"],
["[email protected]", "-keypool=100"],
["[email protected]", "-keypool=100"],
["[email protected]"],
]

  • A timeout of 60s with the expected value of the poisson dist (5s or 7s or whatever) yields a failure rate that is far lower than the failure rate we see due to infrastructure problems or other test problems and races. The issue here is that the nodes are daisy chained and thus the delays add up, which could bring the delay over 60s more likely.

The assumption about test failures that would be fixed by this PR could be biased as in the most cases we have only CI logs that lack data about infrastructure problems.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The current code path, which is skipped in tests with this PR, is not covered by tests in master.

The same might be true for this change. Capping the time might never execute code paths (in other functions) that only run after a long timeout.

@hebasto hebasto changed the title test: Use uniform distribution for random intervals in functional tests test: Add random interval upper bound in regtest Jul 25, 2020
@hebasto

hebasto commented Jul 25, 2020

Copy link
Copy Markdown
Member Author

Reworked.

@MarcoFalke Mind taking another look?

The changes are pretty local, and if they will not justify themselves, they could be easily reverted back 😃

@DrahtBot

DrahtBot commented Jul 26, 2020 •

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:

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.

@hebasto

hebasto commented Jul 29, 2020

Copy link
Copy Markdown
Member Author

Rebased c6d1cbd -> 8a945c0 (pr19588.02 -> pr19588.03) to include the recent CI changes.

Comment thread src/net.cpp Resolved
These changes fix intermittent timeout errors in the functional tests.
@hebasto

hebasto commented Aug 5, 2020

Copy link
Copy Markdown
Member Author

Updated 8a945c0 -> b34b8ed (pr19588.03 -> pr19588.04, diff).

Addressed @instagibbs' comment:

math isn't my strongest suit: Why are we multiplying seconds by 100k to get ms?

Comment thread src/net.cpp
int64_t delta_microseconds = -std::log1p(GetRand(1ULL << 48) * -0.0000000000000035527136788 /* -1/2^48 */) * average_interval_microseconds + 0.5;

// Upper bound to avoid timeouts in the functional tests.
static const bool regtest = gArgs.GetChainName() == CBaseChainParams::REGTEST;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this is really ugly, both doing a string compare here, making the function depend on a global, and doing this at first call (which is not guaranteed to be after initializing the chain name).
Though I don't really have a proposal how to do this differently.

@hebasto hebasto closed this Aug 15, 2020
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Feb 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

5 participants