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(network): graceful cleanup for more consistent CI runs #1960

Merged
merged 8 commits into from
Jul 10, 2024

Conversation

Unique-Divine
Copy link
Member

@Unique-Divine Unique-Divine commented Jul 9, 2024

Purpose / Abstract

Summary by CodeRabbit

  • Refactor

    • Renamed testutilcli to testnetwork across multiple files for better organization and clarity.
    • Improved the Cleanup method to ensure services stop gracefully before cleanup.
    • Updated various structs and functions to enhance network configuration handling.
  • New Features

    • Introduced a logger interface for logging in testing environments.
  • Bug Fixes

    • Enhanced test reliability by ensuring graceful cleanup of services.
  • Tests

    • Updated tests to reflect refactored network package and improved cleanup process.

@Unique-Divine Unique-Divine requested a review from a team as a code owner July 9, 2024 16:35
Copy link
Contributor

coderabbitai bot commented Jul 9, 2024

Warning

Review failed

The pull request is closed.

Walkthrough

This update improves the cleanup process for validator nodes in the testnetwork package, ensuring synchronous cleanup using a wait group and concurrent goroutines for better coordination. Additionally, various files have been refactored for clarity, and package imports have been reorganized or renamed to testnetwork.

Changes

Files Change Summary
x/common/testutil/cli/network.go, x/common/testutil/testnetwork/logger.go, network.go Enhanced cleanup process using wait groups and concurrent goroutines, introduced stopValidatorNode and ValidatorsStopped checks.
CHANGELOG.md Mentioned the addition of a test to ensure consistent CI runs with improved cleanup procedures.
x/common/testutil/cli/util.go Updated startInProcess to assign a logger to val.tmNode.Logger.
x/evm/keeper/grpc_query_test.go, x/common/testutil/testnetwork/query.go Added the strings package import and modified TestTraceTx and TestTraceBlock functions for better comparison of responses.
app/wasmext/wasm_cli_test/cli_test.go, eth/rpc/rpcapi/eth_api_test.go Renamed imports from testutilcli to testnetwork for better organization in CLI test commands and network utilities.
gosdk/export_test.go, gosdk/gosdk_test.go, gosdk/sequence_test.go Renamed cli.Config, cli.Network, and cli.Validator to testnetwork.Config, testnetwork.Network, and testnetwork.Validator.
x/tokenfactory/cli/cli_test.go Updated import references related to testutilcli to testnetwork.
x/common/testutil/testnetwork/... encompassing doc.go, logger.go, network.go, etc. Renamed package from cli to testnetwork, removed unnecessary imports and fields, and reorganized structures for better clarity.

Assessment against linked issues

Objective (Issues) Addressed Explanation
Perform synchronous cleanup of nodes on cleanup (#1955)
Use concurrent goroutines for improved cleanup coordination
Refactor code for better clarity and organization

Poem

In the realm of code, where tests abide,
A network cleaned with enhanced pride,
Goroutines dance, in harmony they flew,
Ensuring validators bid their due.
Under testnetwork, changes sleek,
Our cleanup strong, our structure peak.


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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
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: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 76bdaaa and 73b8e0f.

Files selected for processing (1)
  • x/common/testutil/cli/network.go (2 hunks)
Additional comments not posted (4)
x/common/testutil/cli/network.go (4)

632-645: Approve the use of wait group and concurrent goroutines for cleanup.

The use of a wait group and concurrent goroutines ensures that all services are stopped before cleanup, improving coordination and reliability.


654-665: Verify the retry mechanism for stopping validators.

The retry mechanism with a maximum of 5 retries and 100ms sleep intervals is a good approach. However, ensure that this is sufficient and doesn't introduce any unexpected issues in different environments.


718-725: LGTM!

The ValidatorsStopped function is simple and effective.


727-738: LGTM!

The IsStopped method is straightforward and correctly implemented.

Comment on lines 674 to 716
// stopValidatorNode shuts down all services associated with a validator node.
//
// It gracefully stops the Tendermint node, API, gRPC, gRPC-Web, and JSON-RPC
// services. This function is designed to be run concurrently for multiple
// validators during network cleanup.
//
// The function uses graceful shutdown methods where available to allow ongoing
// operations to complete before terminating. This approach helps prevent
// resource leaks and ensures a clean shutdown of all components.
//
// Parameters:
// - v: Pointer to the Validator struct containing service references.
//
// Note: Errors during shutdown are currently ignored to ensure all services
// attempt to stop, even if one fails. Consider adding error logging for
// debugging in production environments.
func stopValidatorNode(v *Validator) {
if v.tmNode != nil && v.tmNode.IsRunning() {
_ = v.tmNode.Stop()
v.tmNode.Wait() // Wait for the service to fully stop
}

if v.api != nil {
// Close the API server.
// Any blocked "Accept" operations will be unblocked and return errors.
_ = v.api.Close()
}

if v.grpc != nil {
// GracefulStop stops the gRPC server gracefully. It stops the server from
// accepting new connections and RPCs and blocks until all the pending RPCs are
// finished.
v.grpc.GracefulStop()
if v.grpcWeb != nil {
_ = v.grpcWeb.Close()
}
}

if v.jsonrpc != nil {
_ = v.jsonrpc.Close()
}

}
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider adding error logging for debugging.

The stopValidatorNode function currently ignores errors during shutdown. Adding error logging could help with debugging in production environments.

if v.tmNode != nil && v.tmNode.IsRunning() {
  if err := v.tmNode.Stop(); err != nil {
    log.Errorf("Error stopping tmNode: %v", err)
  }
  v.tmNode.Wait() // Wait for the service to fully stop
}

@Unique-Divine Unique-Divine self-assigned this Jul 9, 2024
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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 73b8e0f and 0ebc850.

Files selected for processing (4)
  • CHANGELOG.md (1 hunks)
  • x/common/testutil/cli/network.go (2 hunks)
  • x/common/testutil/cli/util.go (1 hunks)
  • x/evm/keeper/grpc_query_test.go (3 hunks)
Files skipped from review as they are similar to previous changes (1)
  • x/common/testutil/cli/network.go
Additional comments not posted (5)
x/common/testutil/cli/util.go (1)

80-80: LGTM! The logger assignment is correctly added.

This ensures that the Tendermint node's logger is set, which is crucial for logging and debugging.

x/evm/keeper/grpc_query_test.go (3)

8-8: LGTM! The strings package import is appropriate.

The strings package will be useful for the string manipulations in the test functions.


825-831: Verify the root cause of gas value discrepancy.

The change to replace "35062" with "35050" in the expected response ensures the test passes. However, it would be beneficial to investigate why the gas values differ to address the root cause.


904-910: Verify the root cause of gas value discrepancy.

The change to replace "35062" with "35050" in the expected response ensures the test passes. However, it would be beneficial to investigate why the gas values differ to address the root cause.

CHANGELOG.md (1)

83-83: Entry for PR #1960 looks good.

The new entry is clear and concise, providing the necessary context about the change.

Copy link

codecov bot commented Jul 9, 2024

Codecov Report

Attention: Patch coverage is 81.17647% with 16 lines in your changes missing coverage. Please review.

Project coverage is 65.65%. Comparing base (76bdaaa) to head (c93be71).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1960      +/-   ##
==========================================
- Coverage   65.66%   65.65%   -0.02%     
==========================================
  Files         256      257       +1     
  Lines       16392    16433      +41     
==========================================
+ Hits        10764    10789      +25     
- Misses       4829     4840      +11     
- Partials      799      804       +5     
Files Coverage Δ
x/common/testutil/testnetwork/network_config.go 100.00% <ø> (ø)
x/common/testutil/testnetwork/query.go 35.84% <ø> (ø)
x/common/testutil/testnetwork/tx.go 70.00% <ø> (ø)
x/common/testutil/testnetwork/util.go 71.34% <100.00%> (ø)
x/common/testutil/testnetwork/network.go 74.43% <83.33%> (ø)
x/common/testutil/testnetwork/validator_node.go 80.30% <80.30%> (ø)

@Unique-Divine Unique-Divine merged commit d24f7a1 into main Jul 10, 2024
15 checks passed
@Unique-Divine Unique-Divine deleted the ud/test-ci-graceful branch July 10, 2024 00:49
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.

test(testutil): Perform synchronous cleanup of nodes on cleanup
1 participant