Skip to content
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

txscript/hashcache_test: fix flake due to resetting RNG #1689

Merged
merged 2 commits into from
Feb 4, 2021

Commits on Feb 2, 2021

  1. txscript/hashcache_test: always add inputs during getTxn

    TestHashCacheAddContainsHashes flakes fairly regularly when rebasing
    PR btcsuite#1684 with:
        txid <txid> wasn't inserted into cache but was found.
    
    With probabilty 1/10^2 there will be no inputs on the transaction. This
    reduces the entropy in the txid, and I belive is the primary cause of
    the flake.
    cfromknecht committed Feb 2, 2021
    Configuration menu
    Copy the full SHA
    1dd6934 View commit details
    Browse the repository at this point in the history
  2. txscript/hashcache_test: call rand.Seed once in init

    This resolves the more fundamental flake in the unit tests noted in the
    prior commit.
    
    Because multiple unit tests call rand.Seed in parallel, it's possible
    they can be executed with the same unix timestamp (in seconds). If the
    second call happens between generating the hash cache and checking that
    the cache doesn't contain a random txn, the random transaction is in
    fact a duplicate of one generated earlier since the RNG state was reset.
    
    To remedy, we initialize rand.Seed once in the init function.
    cfromknecht committed Feb 2, 2021
    Configuration menu
    Copy the full SHA
    5300a19 View commit details
    Browse the repository at this point in the history