Skip to content

Fix unit test flake TestHistoricalConfDetailsTxIndex - #9549

Merged
guggero merged 10 commits into
lightningnetwork:masterfrom
yyforyongyu:fix-bitcond-test
Feb 26, 2025
Merged

Fix unit test flake TestHistoricalConfDetailsTxIndex#9549
guggero merged 10 commits into
lightningnetwork:masterfrom
yyforyongyu:fix-bitcond-test

Conversation

@yyforyongyu

Copy link
Copy Markdown
Member

Fix a long standing flake found in our unit test,

--- FAIL: TestHistoricalConfDetailsTxIndex (0.00s)
    --- FAIL: TestHistoricalConfDetailsTxIndex/rpc_polling_disabled (11.66s)
        bitcoind_test.go:143: miner height=430, bitcoind height=0
        ...
        bitcoind_test.go:143: miner height=430, bitcoind height=0
        bitcoind_test.go:143: timed out in syncNotifierWithMiner, got err=<nil>, minerHeight=430, bitcoindHeight=0
FAIL
FAIL	github.com/lightningnetwork/lnd/chainntnfs/bitcoindnotify	13.353s
FAIL

It turns out the peer connection between the bitcoind node and the btcd node (miner) is broken, causing the chain backend to never be synced. This unexpected behavior only happens when the test runs multiple times (ranging from 50-ish to 200-ish). To reproduce, remove the second-to-last commit and run,

pkg=chainntnfs/bitcoindnotify
case=TestHistoricalConfDetailsNoTxIndex/rpc_polling_enabled
make flakehunter-unit pkg=$pkg case=$case

@yyforyongyu yyforyongyu added flake fix size/micro small bug fix or feature, less than 15 mins of review, less than 250 labels Feb 25, 2025
@yyforyongyu yyforyongyu added this to the v0.19.0 milestone Feb 25, 2025
@yyforyongyu yyforyongyu self-assigned this Feb 25, 2025
@coderabbitai

coderabbitai Bot commented Feb 25, 2025

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are limited to specific labels.

🏷️ Labels to auto review (1)
  • llm-review

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@guggero guggero left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks a lot for investigating!
The changes look good to me 💯

Interestingly enough it looks like TestFilteredChainView in routing/chainview now fails constantly. Perhaps we were able to turn a flake into an error and with that be able to fix two things at once? Which would be a huge win.

Comment thread Makefile Outdated

#? flakehunter-parallel: Run the integration tests continuously until one fails, running up to ITEST_PARALLELISM test tranches in parallel (default 4)
flakehunter-parallel:
# while [ $$? -eq 0 ]; do GOTRACEBACK=all $(UNIT) -count=1; done

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit: commented out code.

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.

fixed

Comment thread scripts/unit-test-flake-hunter.sh Outdated
counter=0

# Run the command in a loop until it fails.
while output=$(go clean -testcache | make unit-debug log="stdlog trace" pkg=$pkg case=$case timeout=$timeout 2>&1); do

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why do we pipe the output of go clean into the make command? Shouldn't that just be &&?

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.

yeah fixed


var conn *chain.BitcoindConn
err := wait.NoError(func() error {
err = wait.NoError(func() error {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit: belongs to previous commit.

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.

fixed!

"fmt"
"os/exec"
"path/filepath"
"strings"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit: belongs into the next commit.

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.

fixed

This commit adds a script to hunt flakes for a specific unit test with
trace logs. Also rename the make commands to make them more clear on
whether it's a unit test, itest, or paralleled itest.
The config used for the miner is updated to skip banning and debug. For
bitcoind, the config is updated to use a unique port for P2P conn.
Make sure the shutdown of `bitcoind` is finished without any errors.
We change how the `bitcoind` node connects to the miner by creating a
temp RPC client and use it to connect to the miner. In addition we also
assert the connection is made.
@yyforyongyu

Copy link
Copy Markdown
Member Author

Interestingly enough it looks like TestFilteredChainView in routing/chainview now fails constantly. Perhaps we were able to turn a flake into an error and with that be able to fix two things at once? Which would be a huge win.

Yeah glad they are now at least deterministic - pushed a fix, let's see if it passes.

@guggero guggero left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Awesome fixed, thanks a lot!

Comment thread routing/chainview/interface_test.go Outdated
// dedicated miner to generate blocks, cause re-orgs, etc. We'll set up
// this node with a chain length of 125, so we have plenty of BTC to
// play around with.
node := unittest.NewMiner(t, netParams, []string{"--txindex"}, true, 25)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit: extract this code block into a function?

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.

done!

@ellemouton ellemouton left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Epic epic epic!!! Very nice investigation & beautiful PR ✨
lgtm after linter fix

Comment thread Makefile
@$(call print, "Flake hunting unit tests.")
while [ $$? -eq 0 ]; do GOTRACEBACK=all $(UNIT) -count=1; done
#? flakehunter-unit: Run the unit tests continuously until one fails
flakehunter-unit:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

so nice 🔥

}
t.Cleanup(conn.Stop)

// Assert that the connection with the miner is made.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

// Reconnect the miner and the chain backend.
//
// NOTE: The connection should have been made before we perform
// the `syncNotifierWithMiner`. However, due unknown reason, the

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit: s/due unknown reason/due to an unknown reason

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.

fixed!

In this commit we document an unexpected behavior found when connecting
a bitcoind node to a btcd node. We mitigate this in our test by
reconnecting the nodes when the connection is broken. We also limit the
connection made from `bitcoind` to be v1 only.
Prepares for the following commit where we assert the chain backend is
synced to the miner.
This commit makes sure the bitcoind node is synced to the miner when
initialized and returned from `NewBitcoindBackend`.
So each test has its own miner and chainView.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

flake fix size/micro small bug fix or feature, less than 15 mins of review, less than 250

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants