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

refactor(e2e): use alternative errgroup to catch panics #3623

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

gartnera
Copy link
Member

@gartnera gartnera commented Mar 3, 2025

Use an errgroup implementation based on https://github.com/StevenACoffman/errgroup so that panics in the test routines are caught. This will reduce the amount of log spam when you have a test failure in one routine before another routine has even started running.

I just vendored the library to avoid external dependencies. The tests are rewritten to just use require rather than suite.

Closes #3613

Related to #3578

Summary by CodeRabbit

  • New Features
    • Introduced an enhanced error handling module that improves recovery from unexpected issues during concurrent operations.
  • Tests
    • Added comprehensive tests to validate robust error propagation and system reliability.
  • Refactor
    • Updated dependency references to leverage a localized error handling solution for improved maintainability and performance.

@gartnera gartnera added the no-changelog Skip changelog CI check label Mar 3, 2025
@gartnera gartnera requested a review from a team as a code owner March 3, 2025 23:04
Copy link
Contributor

coderabbitai bot commented Mar 3, 2025

📝 Walkthrough

Walkthrough

This pull request replaces the import source for the errgroup package in three files under cmd/zetae2e/local/ from the upstream golang.org/x/sync/errgroup to a project-specific version at github.com/zeta-chain/node/pkg/errgroup. Additionally, it introduces a new errgroup package that wraps the upstream implementation, adding functionality for panic recovery and improved error handling in concurrent goroutines, along with a comprehensive suite of unit tests for these enhancements.

Changes

File(s) Change Summary
cmd/zetae2e/local/bitcoin.go
cmd/zetae2e/local/evm.go
cmd/zetae2e/local/local.go
Removed the import of golang.org/x/sync/errgroup and added an import for github.com/zeta-chain/node/pkg/errgroup in each file.
pkg/errgroup/errgroup.go New package that wraps the upstream errgroup implementation. Introduces functions for panic value conversion, stack trace collection, and wraps goroutines with panic recovery.
pkg/errgroup/errgroup_test.go New unit test suite validating the behavior of the custom errgroup package, including panic recovery, error propagation, and context cancellation scenarios.

Sequence Diagram(s)

sequenceDiagram
    participant Main as Main Goroutine
    participant EG as Errgroup Instance
    participant Worker as Worker Goroutine

    Main->>EG: WithContext(ctx)
    Main->>EG: EG.Go(fn)
    Worker->>EG: Execute fn wrapped in catchPanics
    Worker-->>EG: Pass error or converted panic error
    Main->>EG: Wait()
    EG-->>Main: Return first non-nil error or nil
Loading

Possibly related PRs

Suggested labels

refactor, test, UPGRADE_TESTS

Suggested reviewers

  • lumtis
  • swift1337
  • fbac
  • skosito
✨ Finishing Touches
  • 📝 Generate Docstrings

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.

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 Mar 3, 2025

Codecov Report

Attention: Patch coverage is 95.91837% with 2 lines in your changes missing coverage. Please review.

Project coverage is 64.59%. Comparing base (e9b9bce) to head (ca8a4ff).

Files with missing lines Patch % Lines
pkg/errgroup/errgroup.go 95.91% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #3623      +/-   ##
===========================================
+ Coverage    64.55%   64.59%   +0.04%     
===========================================
  Files          469      470       +1     
  Lines        32723    32772      +49     
===========================================
+ Hits         21123    21170      +47     
- Misses       10639    10641       +2     
  Partials       961      961              
Files with missing lines Coverage Δ
pkg/errgroup/errgroup.go 95.91% <95.91%> (ø)

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)
pkg/errgroup/errgroup_test.go (1)

11-78: Consider reducing duplicated test logic for panic scenarios.

You have multiple tests (e.g., TestPanicWithString, TestPanicWithError, TestPanicWithOtherValue) that follow a nearly identical pattern of verifying that a panic cancels the context. Refactoring shared logic into helper functions or using table-driven tests with sub-tests (via t.Run blocks) can improve maintainability and readability.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e9b9bce and ca8a4ff.

📒 Files selected for processing (5)
  • cmd/zetae2e/local/bitcoin.go (1 hunks)
  • cmd/zetae2e/local/evm.go (1 hunks)
  • cmd/zetae2e/local/local.go (1 hunks)
  • pkg/errgroup/errgroup.go (1 hunks)
  • pkg/errgroup/errgroup_test.go (1 hunks)
✅ Files skipped from review due to trivial changes (3)
  • cmd/zetae2e/local/local.go
  • cmd/zetae2e/local/bitcoin.go
  • cmd/zetae2e/local/evm.go
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.go`: Review the Go code, point out issues relative to ...

**/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

  • pkg/errgroup/errgroup_test.go
  • pkg/errgroup/errgroup.go
🪛 GitHub Check: codecov/patch
pkg/errgroup/errgroup.go

[warning] 30-31: pkg/errgroup/errgroup.go#L30-L31
Added lines #L30 - L31 were not covered by tests

🔇 Additional comments (4)
pkg/errgroup/errgroup_test.go (1)

11-166: Add a test case for panic(nil) to improve coverage.

According to your implementation, panic(nil) would yield a nil return in fromPanicValue. Currently, no test covers that exact scenario, leaving lines 30-31 in fromPanicValue() untested. Consider adding a small test to ensure that panic(nil) doesn’t break the group logic and properly returns nil or no error, thus increasing coverage.

pkg/errgroup/errgroup.go (3)

30-31: Improve test coverage for handling nil panic values.

Lines 30-31 handle the case where the panic value is nil. This logic is currently uncovered by tests, as noted by static analysis. Adding a dedicated test that triggers panic(nil) would ensure this path is tested and guarantee correct behavior.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 30-31: pkg/errgroup/errgroup.go#L30-L31
Added lines #L30 - L31 were not covered by tests


47-62: Well-structured panic handling logic.

Wrapping user-defined functions in catchPanics() effectively captures panics and converts them to errors without introducing undue complexity. This approach is clear and properly isolates panic handling.


64-125: Robust concurrency model with straightforward error propagation.

The design of Group—cancelling the context on the first encountered error or panic and collecting the result with Wait()—is clean and follows established Go concurrency patterns. The named return mechanism in catchPanics() ensures that goroutine panics are captured with minimal overhead.

Copy link
Member

@lumtis lumtis left a comment

Choose a reason for hiding this comment

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

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking:cli no-changelog Skip changelog CI check
Projects
None yet
Development

Successfully merging this pull request may close these issues.

e2e: failure in setup results in hard exit
2 participants