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

test(testutil): try retrying for 'panic: pebbledb: closed' #2162

Merged
merged 2 commits into from
Jan 10, 2025

Conversation

Unique-Divine
Copy link
Member

@Unique-Divine Unique-Divine commented Jan 10, 2025

Purpose / Abstract

An attempt at solving an old problem that's plagued the CI for years (#1918)

Summary by CodeRabbit

  • New Features

    • Introduced a retry mechanism for test suite execution when database is closed
    • Added a new utility function RetrySuiteRunIfDbClosed to handle test suite retries
    • Enhanced EVM functionality with new event emission and address encoding
  • Bug Fixes

    • Resolved issues with database connectivity in test environments
    • Fixed nonce management in state database
    • Addressed potential infinite recursion in ERC20 token contracts
  • Refactor

    • Improved error handling in test suite execution
    • Streamlined VerifyFee function by removing unnecessary arguments
    • Enhanced documentation for various components

Copy link
Contributor

coderabbitai bot commented Jan 10, 2025

Walkthrough

This pull request introduces several enhancements and fixes across the Nibiru blockchain project, primarily focusing on the EVM, bank keeper, and testing infrastructure. The changes include improvements to gas consumption, address encoding, event handling, and test suite robustness. A new utility function RetrySuiteRunIfDbClosed has been added to handle database-related test execution issues, providing more resilient testing across multiple components.

Changes

File Change Summary
CHANGELOG.md Updated with new entries for EVM fixes, bank keeper improvements, and audit-related changes
x/common/testutil/cases.go Added new RetrySuiteRunIfDbClosed utility function for test retry mechanism
Multiple test files Wrapped test suite runs with RetrySuiteRunIfDbClosed for improved error handling

Sequence Diagram

sequenceDiagram
    participant Test Runner
    participant RetrySuiteRunIfDbClosed
    participant Test Suite
    participant Database

    Test Runner->>RetrySuiteRunIfDbClosed: Initiate test run
    RetrySuiteRunIfDbClosed->>Database: Attempt database connection
    alt Database is closed
        RetrySuiteRunIfDbClosed-->>Test Runner: Retry test run
    else Database is open
        RetrySuiteRunIfDbClosed->>Test Suite: Execute test suite
    end
Loading

Possibly related PRs

Suggested reviewers

  • k-yang

Poem

🐰 In the realm of code, where databases dance,
Retry logic hops with a resilient stance
Two attempts to run, no panic can scare
Our tests now bounce back with computational flair!
Nibiru's spirit, robust and bright ✨

Finishing Touches

  • 📝 Generate Docstrings (Beta)

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. (Beta)
  • @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.

Copy link

codecov bot commented Jan 10, 2025

Codecov Report

Attention: Patch coverage is 0% with 20 lines in your changes missing coverage. Please review.

Project coverage is 65.12%. Comparing base (f7a7007) to head (e821519).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
x/common/testutil/cases.go 0.00% 20 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2162      +/-   ##
==========================================
- Coverage   65.20%   65.12%   -0.08%     
==========================================
  Files         277      277              
  Lines       22242    22267      +25     
==========================================
  Hits        14502    14502              
- Misses       6746     6771      +25     
  Partials      994      994              
Files with missing lines Coverage Δ
x/common/testutil/cases.go 23.33% <0.00%> (-46.67%) ⬇️

@Unique-Divine Unique-Divine marked this pull request as ready for review January 10, 2025 19:51
@Unique-Divine Unique-Divine requested a review from a team as a code owner January 10, 2025 19:51
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
x/common/testutil/cases.go (1)

43-74: Consider adding delay between retries and making panic message configurable.

The implementation is solid, but could be enhanced with:

  1. A delay between retries to prevent immediate retries
  2. A configurable panic message parameter for reusability
-func RetrySuiteRunIfDbClosed(t *testing.T, runTest func(), maxRetries int) {
-	panicMessage := "pebbledb: closed"
+func RetrySuiteRunIfDbClosed(t *testing.T, runTest func(), maxRetries int, retryDelay time.Duration) {
+	panicMessage := "pebbledb: closed" // TODO: Consider making this configurable
	for attempt := 0; attempt < maxRetries; attempt++ {
		panicked := false

		func() {
			defer func() {
				if r := recover(); r != nil {
					if errMsg, ok := r.(string); ok && strings.Contains(errMsg, panicMessage) {
						t.Logf("Recovered from panic on attempt %d: %v", attempt, r)
						panicked = true
					} else {
						panic(r) // Re-panic if it's not the specific error
					}
				}
			}()

			runTest()
		}()

		if !panicked {
			t.Logf("Test suite succeeded on attempt %d", attempt)
			return
		}

+		if attempt < maxRetries-1 {
+			t.Logf("Waiting %v before retry attempt %d", retryDelay, attempt+1)
+			time.Sleep(retryDelay)
+		}
		t.Logf("Retrying test suite: attempt %d", attempt+1)
	}

	t.Fatalf("Test suite failed after %d attempts due to '%s'", maxRetries, panicMessage)
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1ed351f and e821519.

📒 Files selected for processing (8)
  • CHANGELOG.md (1 hunks)
  • app/wasmext/wasm_cli_test/cli_test.go (1 hunks)
  • eth/rpc/rpcapi/eth_api_test.go (1 hunks)
  • x/common/testutil/cases.go (2 hunks)
  • x/common/testutil/testnetwork/network_test.go (1 hunks)
  • x/oracle/keeper/app_test.go (1 hunks)
  • x/sudo/cli/cli_test.go (1 hunks)
  • x/tokenfactory/cli/cli_test.go (1 hunks)
👮 Files not reviewed due to content moderation or server errors (4)
  • x/tokenfactory/cli/cli_test.go
  • x/sudo/cli/cli_test.go
  • eth/rpc/rpcapi/eth_api_test.go
  • CHANGELOG.md
🔇 Additional comments (4)
x/common/testutil/cases.go (1)

39-42: LGTM! Well-documented function with clear purpose.

The documentation clearly explains the purpose and context of the function, linking to the relevant issue.

x/common/testutil/testnetwork/network_test.go (1)

25-27: LGTM! Proper usage of retry mechanism.

The implementation correctly uses the retry mechanism with a reasonable number of retries (2).

app/wasmext/wasm_cli_test/cli_test.go (1)

143-145: LGTM! Consistent implementation of retry mechanism.

The implementation follows the same pattern as other files, using 2 retries.

x/oracle/keeper/app_test.go (1)

180-182: LGTM! Consistent implementation of retry mechanism.

The implementation follows the same pattern as other files, using 2 retries.

@Unique-Divine Unique-Divine merged commit 8db476f into main Jan 10, 2025
20 checks passed
@Unique-Divine Unique-Divine deleted the ud/pebbledb-closed branch January 10, 2025 20:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant