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

chore: pass knuu as an argument to the testnet.New #3952

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

mojtaba-esk
Copy link
Member

As pointed out before in one of the comments, if we pass knuu as an argument to the testnet constructor, user will have more flexibility in playing with knuu options and can optimize the resource consumption based on the test requirements.

This PR attempts to achieve that goal.

@mojtaba-esk mojtaba-esk self-assigned this Oct 8, 2024
@mojtaba-esk mojtaba-esk requested a review from a team as a code owner October 8, 2024 15:11
@mojtaba-esk mojtaba-esk requested review from rootulp and staheri14 and removed request for a team October 8, 2024 15:11
Copy link
Contributor

coderabbitai bot commented Oct 8, 2024

📝 Walkthrough
📝 Walkthrough

Walkthrough

The pull request introduces modifications to several end-to-end test files to integrate the Knuu package for improved test execution management. Key changes include the initialization of Knuu instances with unique identifiers, the introduction of a new Options structure for testnet creation, and enhanced logging for better visibility during test execution. The core logic of existing tests remains intact, but the overall structure and error handling have been improved to streamline the testing process.

Changes

File Path Change Summary
test/e2e/benchmark/benchmark.go Modified NewBenchmarkTest to integrate Knuu; established context with cancellation and improved error handling for testnet creation.
test/e2e/main.go Added constant timeFormat for timestamp formatting; no changes to existing logic.
test/e2e/major_upgrade_v2.go Modified MajorUpgradeToV2 to integrate Knuu; added logging; updated testnet creation to use testnet.Options.
test/e2e/major_upgrade_v3.go Updated MajorUpgradeToV3 to include Knuu; adjusted upgrade height and testnet creation.
test/e2e/minor_version_compatibility.go Updated MinorVersionCompatibility to include Knuu initialization and improved logging; utilized testnet.Options.
test/e2e/simple.go Modified E2ESimple to initialize Knuu and updated testnet creation with testnet.Options.
test/e2e/testnet/testnet.go Introduced Options structure; modified New function signature; removed Knuu method from Testnet.

Possibly related issues

Possibly related PRs

  • test(e2e benchmark): refactors E2EThroughput #3395: The MajorUpgradeToV2 function in this PR integrates the Knuu package similarly to the main PR, enhancing test management and updating the testnet creation process to utilize the Options struct.
  • feat: use proxy instead of port forwards #3505: This PR modifies the benchmark.go file to streamline the testnet setup, which aligns with the changes in the main PR that also enhance test management through the integration of the Knuu package.
  • test: make nodes also restart after upgrading in knuu #3556: The changes in the MajorUpgradeToV2 function include adjustments to the testnet creation process, which is relevant to the modifications made in the main PR regarding testnet initialization.
  • test: v3 e2e upgrade #3910: The MajorUpgradeToV3 function introduces a new upgrade process that utilizes the Knuu package, similar to the enhancements made in the main PR for better test management.
  • chore: update e2e tests to knuu 0.16.1 #3911: This PR updates the e2e tests to use the latest version of Knuu, which is directly relevant to the main PR's integration of the Knuu package for improved test management.

Suggested labels

chore, WS: Big Blonks 🔭

Suggested reviewers

  • cmwaters
  • ninabarbakadze
  • staheri14
  • evan-forbes
  • rootulp

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:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • 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 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
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: 3

🧹 Outside diff range and nitpick comments (3)
test/e2e/simple.go (1)

25-30: Initialize Knuu with appropriate options

The Knuu instance is initialized correctly with the specified options:

  • Scope: Provides isolation between test runs.
  • ProxyEnabled: Allows for network proxying if required.

Consider whether you need to uncomment and set the Timeout option based on your test requirements.

If timeouts are a concern for longer-running tests, you might uncomment the Timeout option:

    		// if the tests timeout, pass the timeout option
-		// Timeout: 120 * time.Minute,
+		Timeout: 120 * time.Minute,
test/e2e/major_upgrade_v2.go (2)

21-21: Consider declaring testName as a constant

Since testName is a value that does not change, declaring it as a constant improves code readability and conveys its immutability.

Apply this diff to declare testName as a constant:

+const testName = "MajorUpgradeToV2"

 var (
-	testName      = "MajorUpgradeToV2"
 	numNodes      = 4
 	upgradeHeight = int64(10)
 )

33-34: Consider removing or uncommenting the Timeout option

The Timeout option is currently commented out. If it's not needed, consider removing it to keep the code clean. If it might be used in the future, perhaps add a comment explaining under what circumstances it should be enabled.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between b99ef0c and c0589bd.

📒 Files selected for processing (4)
  • test/e2e/major_upgrade_v2.go (1 hunks)
  • test/e2e/minor_version_compatibility.go (2 hunks)
  • test/e2e/simple.go (1 hunks)
  • test/e2e/testnet/testnet.go (1 hunks)
🧰 Additional context used
🔇 Additional comments (16)
test/e2e/testnet/testnet.go (4)

33-39: LGTM: Well-structured TestnetOptions struct

The introduction of the TestnetOptions struct is a good design choice. It encapsulates all the parameters previously passed to the New function, improving flexibility and making future additions easier. The struct is well-organized with clear field names.


41-49: LGTM: Improved New function with TestnetOptions

The changes to the New function are well-implemented. The new signature simplifies the function call by accepting a single TestnetOptions parameter, which aligns with the PR objective of passing knuu as an argument. The function body correctly initializes the Testnet struct using fields from the opts parameter.


Line range hint 1-1: Summary: Changes align well with PR objectives

The modifications in this file, including the introduction of TestnetOptions, updates to the New function, and removal of the Knuu method, align well with the PR objective of passing knuu as an argument to the testnet constructor. These changes enhance the flexibility of the testnet constructor and allow for better customization of testnet configurations.

The code structure has been improved, making it easier to add new options in the future. However, please ensure that all instances of t.Knuu() in the codebase are updated to directly access the knuu field of the Testnet struct.


Line range hint 1-1: Verify impact of removing the Knuu method

The removal of the Knuu method from the Testnet struct simplifies the code and reduces unnecessary abstraction. However, this change might impact existing code that uses the Knuu method.

Please run the following script to check for any remaining usage of the Knuu method:

If the script returns any results, those occurrences should be updated to directly access the knuu field of the Testnet struct.

test/e2e/simple.go (7)

12-12: Import Knuu package for testnet integration

The addition of the import "github.com/celestiaorg/knuu/pkg/knuu" is appropriate for integrating Knuu into the testnet. This allows for enhanced testnet management and flexibility.


19-19: Define 'testName' as a constant

Defining testName as a constant improves code readability and maintainability. This makes it easier to reference and modify the test name if needed.


24-24: Generate a unique identifier for Knuu scope

Creating a unique identifier using testName and the current timestamp ensures that each test run operates in a distinct scope. This is a good practice to prevent conflicts between concurrent test executions.


31-31: Proper error handling after Knuu initialization

Using testnet.NoError("failed to initialize Knuu", err) ensures that any errors during Knuu initialization are appropriately handled and reported. This enhances the robustness of the test setup.


32-32: Handle stop signals for Knuu gracefully

Calling kn.HandleStopSignal(ctx) allows the Knuu instance to handle termination signals properly, ensuring resources are cleaned up and processes are stopped gracefully.


33-33: Log Knuu initialization details

Logging the initialization details of Knuu, including the scope and testName, provides valuable information for debugging and auditing test runs.


35-40: Pass Knuu instance to TestnetOptions

Integrating the Knuu instance into testnet.New by passing it through testnet.TestnetOptions enhances the testnet's flexibility and control. This change aligns with the PR's objective to pass knuu as an argument to testnet.New.

test/e2e/minor_version_compatibility.go (4)

18-18: Importing Knuu package: Looks good

The addition of the Knuu package import is necessary for integrating Knuu into the test setup.


22-25: Constants declaration improves code clarity

Defining testName and numNodes as constants enhances readability and maintainability.


51-53: Initialization and logging of Knuu instance: Approved

Handling the stop signal and logging the initialization details ensures proper resource management and traceability.


54-59: Passing Knuu instance to TestnetOptions

Including the Knuu instance in TestnetOptions allows for flexible test network configuration and aligns with the objective of passing Knuu as an argument.

test/e2e/major_upgrade_v2.go (1)

15-15: Importing Knuu package is appropriate

The addition of the Knuu package import is necessary for the new functionality introduced.

test/e2e/minor_version_compatibility.go Outdated Show resolved Hide resolved
test/e2e/major_upgrade_v2.go Outdated Show resolved Hide resolved
test/e2e/major_upgrade_v2.go Outdated Show resolved Hide resolved
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: 2

🧹 Outside diff range and nitpick comments (3)
test/e2e/simple.go (1)

24-33: LGTM: Knuu initialization added with proper error handling and logging.

The Knuu initialization is well-implemented with a unique identifier, proper error handling, and informative logging. This addition enhances the test setup and provides better control over the test environment.

Consider reviewing the commented-out timeout option. If it's necessary for some scenarios, you might want to make it configurable or document why it's commented out.

test/e2e/testnet/testnet.go (1)

Potential Impact of Removing the Knuu Method

The removal of the Knuu method from the Testnet struct may affect existing code that references it. Please review the following locations to ensure that the removal does not introduce issues:

  • test/e2e/simple.go

    • Line 1: testnet.NoError("failed to initialize Knuu", err)
    • Line 2: logger.Println("Knuu initialized", "scope", kn.Scope, "testName", testName)
    • Line 3: Knuu: kn,
  • test/e2e/major_upgrade_v2.go

    • Line 1: testnet.NoError("failed to initialize Knuu", err)
    • Line 2: logger.Println("Knuu initialized", "scope", kn.Scope, "testName", testName)
    • Line 3: Knuu: kn,
  • test/e2e/testnet/txsimNode.go

    • Line 1: knuu *knuu.Knuu,
  • test/e2e/testnet/testnet.go

    • Line 1: knuu *knuu.Knuu
    • Line 2: Knuu *knuu.Knuu
    • Line 3: knuu: opts.Knuu,
  • test/e2e/testnet/node.go

    • Line 1: kn *knuu.Knuu,
  • test/e2e/minor_version_compatibility.go

    • Line 1: testnet.NoError("failed to initialize Knuu", err)
    • Line 2: logger.Println("Knuu initialized", "scope", kn.Scope, "testName", testName)
    • Line 3: Knuu: kn,
🔗 Analysis chain

Line range hint 1-1: Verify the impact of removing the Knuu method

The Knuu method has been removed from the Testnet struct. While this change aligns with the new approach of passing knuu as an argument, please verify that this removal doesn't negatively impact any existing code that might rely on this method. Consider adding a comment explaining the rationale behind this removal if it's intentional.

To check for potential impacts, you can run the following command:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any remaining usage of the Knuu method
rg '\bKnuu\(\)' --type go

Length of output: 27


Script:

#!/bin/bash
# Search for any remaining usage of the Knuu identifier in Go files
rg 'Knuu' --type go

Length of output: 958

test/e2e/major_upgrade_v2.go (1)

21-21: Avoid hardcoding the test name

While defining testName as "MajorUpgradeToV2" works, consider deriving it dynamically from the function name or using a constant to prevent potential discrepancies if the function name changes.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between b99ef0c and c0589bd.

📒 Files selected for processing (4)
  • test/e2e/major_upgrade_v2.go (1 hunks)
  • test/e2e/minor_version_compatibility.go (2 hunks)
  • test/e2e/simple.go (1 hunks)
  • test/e2e/testnet/testnet.go (1 hunks)
🧰 Additional context used
🔇 Additional comments (17)
test/e2e/simple.go (3)

12-12: LGTM: Knuu package import added.

The import for the Knuu package is correctly added and is necessary for the subsequent Knuu initialization in the function.


19-20: LGTM: Test name constant added.

The addition of the testName constant is a good practice. It improves code readability and maintainability by centralizing the test name definition.


Line range hint 1-91: Summary: E2ESimple function successfully updated to incorporate Knuu.

The changes to the E2ESimple function effectively integrate the Knuu package for improved test execution management. Key improvements include:

  1. Proper initialization of a Knuu instance with a unique identifier.
  2. Enhanced testnet creation using the new TestnetOptions structure.
  3. Improved logging for better visibility during test execution.

These modifications align well with the PR objectives, enhancing the flexibility and control of the testnet setup while maintaining the core logic of the existing test.

test/e2e/testnet/testnet.go (2)

33-39: LGTM: New TestnetOptions struct improves code organization

The introduction of the TestnetOptions struct is a good improvement. It encapsulates all the parameters previously passed to the New function, making the code more organized and easier to maintain. This change also aligns with the PR objective of passing knuu as an argument.


41-49: LGTM: New function signature improves flexibility and meets PR objective

The changes to the New function are well-implemented. The new signature, which takes a single TestnetOptions parameter, simplifies function calls and improves flexibility for future additions. The function body correctly uses the fields from the TestnetOptions struct, including the initialization of the knuu field, which meets the PR objective of passing knuu as an argument.

test/e2e/minor_version_compatibility.go (5)

18-18: Added import for Knuu package

The addition of github.com/celestiaorg/knuu/pkg/knuu import integrates Knuu functionalities into the test environment.


22-25: Constants 'testName' and 'numNodes' added for clarity

Defining testName and numNodes as constants improves code readability and maintainability by clearly identifying the test's purpose and the number of nodes used.


42-43: Unique identifier for Knuu scope

Constructing the identifier using the test name and current timestamp ensures a unique scope for each test run, preventing potential conflicts in test environments.


51-51: Ensure graceful shutdown with 'HandleStopSignal'

Calling kn.HandleStopSignal(ctx) ensures that the Knuu instance handles stop signals appropriately, allowing for a clean and graceful shutdown of the test environment.


54-59: Updated 'testnet.New' call to include Knuu instance

Incorporating the Knuu instance into testnet.New enhances the flexibility and modularity of the testnet setup, allowing for better management and customization of the test environment.

test/e2e/major_upgrade_v2.go (7)

15-15: Importing Knuu package

The import of "github.com/celestiaorg/knuu/pkg/knuu" correctly allows the use of the Knuu package for managing test execution.


29-35: Initializing Knuu instance with unique identifier

The Knuu instance is initialized with a unique identifier, which is essential for isolating test environments. The options set, including ProxyEnabled, are appropriate.


36-36: Error handling after Knuu initialization

The error check using testnet.NoError ensures that any issues during Knuu initialization are properly handled.


38-38: Handling stop signals for graceful shutdown

Using kn.HandleStopSignal(ctx) allows the test to respond gracefully to termination signals, improving test robustness.


39-39: Enhanced logging with Knuu initialization details

Logging the initialization of Knuu with details about the scope and test name improves traceability and debugging capability.


42-47: Updating testnet creation to include Knuu instance

Passing the Knuu instance within testnet.TestnetOptions when creating the testnet ensures that the testnet is aware of the Knuu environment.


42-47: Verify consistency of testnet.New usage across the codebase

With the updated signature of testnet.New to accept TestnetOptions, ensure all other invocations of testnet.New are updated accordingly to prevent potential errors.

Run the following script to identify all usages of testnet.New:

Review each occurrence to confirm that they pass TestnetOptions with the necessary parameters, including the Knuu instance if required.

✅ Verification successful

All testnet.New invocations are consistent with the updated signature including the Knuu parameter. No issues found.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find all calls to testnet.New that need to be reviewed.

rg --type go --no-heading --line-number 'testnet\.New\(ctx,'

Length of output: 333


Script:

#!/bin/bash
# Description: Verify that all testnet.New calls include the Knuu parameter in TestnetOptions.

ast-grep --lang go --pattern 'testnet\.New($_, testnet\.TestnetOptions{ $$$, Knuu: $_, $$$ })' --invert

Length of output: 305


Script:

#!/bin/bash
# Description: Verify that all testnet.New calls include the Knuu parameter in TestnetOptions.

rg --type go --no-heading --line-number 'testnet\.New\(ctx,\s*testnet\.TestnetOptions\{' | grep -v 'Knuu:'

Length of output: 377


Script:

#!/bin/bash
# Description: Verify that all testnet.New calls include the Knuu parameter in TestnetOptions.

rg --type go --no-heading --line-number 'testnet\.New\(ctx,\s*testnet\.TestnetOptions\{' | grep -v 'Knuu\s*:'

Length of output: 382


Script:

#!/bin/bash
# Description: Identify all testnet.New calls and check for the presence of the Knuu parameter.

# Step 1: Extract all testnet.New calls with their TestnetOptions
ast-grep --lang go --pattern 'testnet.New(ctx, testnet.TestnetOptions{ $$$ })' > all_testnet_new_calls.txt

# Step 2: Identify calls that do not include the Knuu parameter
grep -L 'Knuu:' all_testnet_new_calls.txt

Length of output: 122

test/e2e/simple.go Outdated Show resolved Hide resolved
test/e2e/minor_version_compatibility.go Outdated Show resolved Hide resolved
Copy link
Collaborator

@rootulp rootulp left a comment

Choose a reason for hiding this comment

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

CI is failing b/c NewBenchmarkTest also needs to be updated to account for the TestnetOptions modification

test/e2e/major_upgrade_v2.go Outdated Show resolved Hide resolved
@rootulp rootulp marked this pull request as draft October 8, 2024 15:34
@mojtaba-esk mojtaba-esk requested review from a team and ninabarbakadze and removed request for a team October 9, 2024 06:33
@mojtaba-esk mojtaba-esk marked this pull request as ready for review October 9, 2024 07:09
@mojtaba-esk
Copy link
Member Author

CI is failing b/c NewBenchmarkTest also needs to be updated to account for the TestnetOptions modification

Thanks for pointing it out. now it is fixed.

@mojtaba-esk mojtaba-esk enabled auto-merge (squash) October 9, 2024 07:10
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: 2

🧹 Outside diff range and nitpick comments (5)
test/e2e/major_upgrade_v2.go (1)

29-39: LGTM: Knuu initialization implemented correctly

The Knuu initialization has been implemented effectively:

  • A unique identifier is created for each test run.
  • Knuu options are set appropriately, including proxy enablement.
  • Error handling is implemented correctly.
  • The logging statement has been updated to use Printf as suggested.

Consider uncommenting and configuring the Timeout option if extended test durations are anticipated.

test/e2e/testnet/testnet.go (2)

41-49: LGTM: Improved New function with Options

The refactoring of the New function to use the Options struct simplifies the function signature and improves readability. The changes correctly utilize the fields from the opts parameter, including the knuu field, which aligns with the PR objective.

Consider adding basic validation for required fields in the Options struct to provide more informative error messages. For example:

if opts.Knuu == nil {
    return nil, errors.New("knuu is required in Options")
}

Remaining usages of the Knuu method found

The removal of the Knuu method from the Testnet struct is not fully completed. The following files still contain usages of Knuu:

  • test/e2e/simple.go
  • test/e2e/testnet/txsimNode.go
  • test/e2e/testnet/node.go
  • test/e2e/major_upgrade_v2.go
  • test/e2e/minor_version_compatibility.go
  • test/e2e/benchmark/benchmark.go

Please update these instances to use the new knuu field from the Testnet struct directly.

🔗 Analysis chain

Line range hint 1-1: Verify impact of removing Knuu method

The removal of the Knuu method from the Testnet struct aligns with the new approach of passing knuu as an argument in the Options struct. However, it's crucial to ensure that all previous usages of this method have been appropriately updated throughout the codebase.

Please run the following script to check for any remaining usages of the Knuu method:

If the script returns any results, those occurrences should be updated to use the new knuu field from the Testnet struct directly.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any remaining usages of the Knuu method
rg --type go 'Knuu\(\)' --glob '!test/e2e/testnet/testnet.go'

Length of output: 63


Script:

#!/bin/bash
# Search for any remaining usages of Knuu in the codebase excluding testnet.go
rg --type go 'Knuu\b' --glob '!test/e2e/testnet/testnet.go'

Length of output: 933

test/e2e/benchmark/benchmark.go (2)

36-37: Clarify Context Usage in HandleStopSignal

The comment indicates that context.Background() is used to allow HandleStopSignal to function after this function returns. It might be clearer to explain why a new background context is appropriate here, especially since ctx was created earlier. Consistency in context usage can help prevent confusion.


39-40: Enhance Logging for Better Visibility

The log message "Knuu initialized with scope %s" provides useful information. Consider including additional context if available, such as the identifier or any relevant configuration details, to aid in debugging and monitoring.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between c0589bd and a51789c.

📒 Files selected for processing (5)
  • test/e2e/benchmark/benchmark.go (2 hunks)
  • test/e2e/major_upgrade_v2.go (1 hunks)
  • test/e2e/minor_version_compatibility.go (2 hunks)
  • test/e2e/simple.go (1 hunks)
  • test/e2e/testnet/testnet.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • test/e2e/minor_version_compatibility.go
  • test/e2e/simple.go
🧰 Additional context used
🔇 Additional comments (6)
test/e2e/major_upgrade_v2.go (4)

15-15: LGTM: Knuu package import added correctly

The import for the Knuu package has been added appropriately, aligning with the existing import structure and supporting the new test management features.


21-21: LGTM: Test name variable added

The testName variable has been appropriately declared and initialized, providing a clear identifier for the test which enhances readability and maintainability.


55-55: LGTM: Logging statement updated as suggested

The logging statement has been correctly updated to use Printf, allowing for proper formatting of the log message with variables. This change addresses the suggestion made in a previous review comment.


Line range hint 19-147: Overall changes improve test management while preserving core logic

The modifications to the MajorUpgradeToV2 function successfully integrate Knuu for enhanced test management and update the testnet creation process. These changes provide better control over the test environment and improve code clarity without altering the core upgrade verification logic.

Key improvements:

  1. Integration of Knuu for test management
  2. Use of structured options for testnet creation
  3. Improved logging

These changes enhance the maintainability and flexibility of the test setup while preserving its fundamental functionality.

test/e2e/testnet/testnet.go (1)

33-39: LGTM: Well-structured Options struct

The introduction of the Options struct is a good design choice. It encapsulates related parameters, making the code more maintainable and extensible. This change aligns well with the PR objective of passing knuu as an argument and improves overall code organization.

test/e2e/benchmark/benchmark.go (1)

41-48: Verify Integration of Knuu with testnet.New

The testnet.New function now includes the Knuu option:

testNet, err := testnet.New(testnet.Options{
    // ...
    Knuu: kn,
})

Ensure that the testnet.Options struct and the testnet.New function are updated to accept and utilize the Knuu instance correctly. Verify that all downstream components handle the Knuu field as expected.

To confirm, you can check the implementation of testnet.Options and testnet.New to ensure they accommodate the new Knuu parameter.

test/e2e/benchmark/benchmark.go Show resolved Hide resolved
rootulp
rootulp previously approved these changes Oct 9, 2024
Copy link
Collaborator

@rootulp rootulp left a comment

Choose a reason for hiding this comment

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

LGTM

ctx, cancel := context.WithCancel(context.Background())
defer cancel()

identifier := fmt.Sprintf("%s_%s", name, time.Now().Format("20060102_150405"))
Copy link
Collaborator

Choose a reason for hiding this comment

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

[optional] this could extract a constant for the time format and reuse that in other places

Copy link
Member Author

Choose a reason for hiding this comment

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

done

func (t *Testnet) Knuu() *knuu.Knuu {
return t.knuu
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

[question] is this getter no longer helpful?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not really as the user passes the knuu object, so they can use it on their end the way they need.

@celestia-bot celestia-bot requested a review from a team October 9, 2024 14:22
Copy link
Collaborator

@rootulp rootulp left a comment

Choose a reason for hiding this comment

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

golangci-lint is complaining

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: 5

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between a51789c and 6d00b69.

📒 Files selected for processing (4)
  • test/e2e/benchmark/benchmark.go (2 hunks)
  • test/e2e/major_upgrade_v2.go (1 hunks)
  • test/e2e/minor_version_compatibility.go (2 hunks)
  • test/e2e/simple.go (1 hunks)
🧰 Additional context used
🪛 GitHub Check: test / test-coverage
test/e2e/major_upgrade_v2.go

[failure] 29-29:
undefined: timeFormat

test/e2e/minor_version_compatibility.go

[failure] 42-42:
undefined: timeFormat

test/e2e/simple.go

[failure] 24-24:
undefined: timeFormat

🪛 GitHub Check: test / test-short
test/e2e/major_upgrade_v2.go

[failure] 29-29:
undefined: timeFormat

test/e2e/minor_version_compatibility.go

[failure] 42-42:
undefined: timeFormat

test/e2e/simple.go

[failure] 24-24:
undefined: timeFormat

🪛 GitHub Check: lint / golangci-lint
test/e2e/major_upgrade_v2.go

[failure] 29-29:
undefined: timeFormat

test/e2e/minor_version_compatibility.go

[failure] 42-42:
undefined: timeFormat

test/e2e/simple.go

[failure] 24-24:
undefined: timeFormat (typecheck)

🔇 Additional comments (18)
test/e2e/simple.go (5)

12-12: LGTM: Knuu package import added.

The addition of the Knuu package import is consistent with the PR objective of integrating Knuu for improved test execution management.


19-33: LGTM: Constant definition and Knuu initialization added.

The addition of the testName constant and the Knuu initialization with a unique identifier aligns well with the PR objective. This change enhances the flexibility and traceability of the test execution.

🧰 Tools
🪛 GitHub Check: test / test-coverage

[failure] 24-24:
undefined: timeFormat

🪛 GitHub Check: test / test-short

[failure] 24-24:
undefined: timeFormat

🪛 GitHub Check: lint / golangci-lint

[failure] 24-24:
undefined: timeFormat (typecheck)


35-40: LGTM: Testnet creation updated to use Options structure.

The modification to use testnet.Options and include the Knuu instance aligns perfectly with the PR objective. This change enhances the flexibility of testnet creation while maintaining other necessary parameters.


48-48: LGTM: Logging statement updated to use testName constant.

The use of the testName constant in the logging statement improves consistency and maintainability of the code.


19-48: Overall changes align well with PR objectives.

The modifications to the E2ESimple function successfully integrate the Knuu package and enhance the flexibility of testnet creation. These changes align perfectly with the PR objectives of allowing the "knuu" parameter to be passed as an argument and improving test execution management.

The core logic of the function remains intact, ensuring that existing functionality is preserved while new features are added. This approach maintains the integrity of the tests while improving their configurability and efficiency.

🧰 Tools
🪛 GitHub Check: test / test-coverage

[failure] 24-24:
undefined: timeFormat

🪛 GitHub Check: test / test-short

[failure] 24-24:
undefined: timeFormat

🪛 GitHub Check: lint / golangci-lint

[failure] 24-24:
undefined: timeFormat (typecheck)

test/e2e/minor_version_compatibility.go (4)

18-18: LGTM: Knuu package import added

The addition of the Knuu package import aligns with the PR objectives to enhance test execution management. This change is appropriate and necessary for the subsequent modifications in the code.


22-25: LGTM: Constants added for improved readability

The addition of testName and numNodes constants enhances code readability and maintainability. Using testName for logging is a good practice that improves the clarity of log messages.


54-59: LGTM: Testnet initialization updated

The update to use a TestnetOptions struct for testnet initialization improves the organization and clarity of the test setup. The inclusion of the Knuu instance in the options is consistent with the PR objectives and enhances the flexibility of the testnet constructor.


Line range hint 147-156: LGTM: New getAllVersions() function added

The addition of the getAllVersions() function is a good enhancement. It retrieves all version tags using Git and returns them as a space-separated string. This function improves the flexibility of version selection for testing, which aligns well with the overall objectives of the PR.

test/e2e/major_upgrade_v2.go (5)

15-15: LGTM: Knuu package import added

The addition of the Knuu package import is consistent with the PR objectives to enhance test management.


21-21: LGTM: Test name variable added

The addition of the testName variable improves code readability and maintainability, aligning with the PR objectives to enhance test management.


29-39: LGTM: Knuu initialization added

The addition of Knuu initialization and configuration is consistent with the PR objectives to enhance test management. The use of a unique identifier for the Knuu instance is a good practice.

🧰 Tools
🪛 GitHub Check: test / test-coverage

[failure] 29-29:
undefined: timeFormat

🪛 GitHub Check: test / test-short

[failure] 29-29:
undefined: timeFormat

🪛 GitHub Check: lint / golangci-lint

[failure] 29-29:
undefined: timeFormat


55-55: LGTM: Logging statement updated

The updated logging statement improves the clarity of the test output by including the test name. The formatting is correct and consistent with Go's Printf function.


Line range hint 1-180: Overall changes improve test management while preserving core functionality

The modifications to the MajorUpgradeToV2 function successfully integrate the Knuu package for improved test execution management. The changes align with the PR objectives to enhance the flexibility of the testnet constructor and improve the overall usability and efficiency of the testnet setup.

Key improvements include:

  1. Initialization of Knuu instances with unique identifiers
  2. Introduction of a new Options structure for testnet creation
  3. Enhanced logging for better visibility during test execution

Importantly, the core logic for checking application versions before and after the upgrade remains intact, ensuring that the original functionality is preserved.

🧰 Tools
🪛 GitHub Check: test / test-coverage

[failure] 29-29:
undefined: timeFormat

🪛 GitHub Check: test / test-short

[failure] 29-29:
undefined: timeFormat

🪛 GitHub Check: lint / golangci-lint

[failure] 29-29:
undefined: timeFormat

test/e2e/benchmark/benchmark.go (4)

15-16: LGTM: New import added for Knuu package

The addition of the Knuu package import is appropriate for the changes made in the NewBenchmarkTest function.


18-20: LGTM: Time format constant added

The addition of the timeFormat constant is a good practice for maintainability. It addresses a previous suggestion to extract the time format into a constant.


43-51: LGTM: Improved logging and testnet initialization

The added logging for Knuu initialization and the use of an Options struct for testnet.New are good improvements. They enhance debugging capabilities and code maintainability.


52-53: LGTM: Error handling added for testnet creation

The addition of error handling for the testnet creation is a good practice. It ensures that any failures in this critical step are immediately caught and reported.

test/e2e/simple.go Show resolved Hide resolved
test/e2e/minor_version_compatibility.go Show resolved Hide resolved
test/e2e/major_upgrade_v2.go Show resolved Hide resolved
test/e2e/major_upgrade_v2.go Show resolved Hide resolved
test/e2e/benchmark/benchmark.go Show resolved Hide resolved
@celestia-bot celestia-bot requested a review from a team October 9, 2024 15:09
@mojtaba-esk
Copy link
Member Author

golangci-lint is complaining

forgot to save a file, pushed again

rootulp
rootulp previously approved these changes Oct 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: 3

🧹 Outside diff range and nitpick comments (3)
test/e2e/benchmark/benchmark.go (1)

45-52: LGTM: Improved testnet creation with Options struct and error handling.

The use of an Options struct for testnet creation is a good improvement. It enhances code readability and makes it easier to add or modify options in the future. The addition of error handling is also a positive change.

Consider wrapping the error with additional context:

-testnet.NoError("failed to create testnet", err)
+testnet.NoError("failed to create testnet", fmt.Errorf("creating testnet with Knuu: %w", err))

This change would provide more context about where the error occurred, making debugging easier.

test/e2e/testnet/testnet.go (2)

41-49: Approved: Simplified New function with Options struct

The updated New function signature using the Options struct simplifies the API and improves flexibility. The function body correctly utilizes the fields from the Options struct.

Consider adding basic validation for the Options struct fields, such as checking for nil values where appropriate, to improve error handling and provide more informative error messages to the user.


Line range hint 62-65: Removal of Knuu method aligns with new design

The removal of the Knuu method is consistent with the new approach where the user passes the knuu object directly. This change improves encapsulation and gives users more control over how they use the knuu object.

Consider updating the package documentation to reflect this change and provide guidance on how users should now interact with the knuu object.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between c17e943 and 3d3d3d6.

📒 Files selected for processing (7)
  • test/e2e/benchmark/benchmark.go (2 hunks)
  • test/e2e/main.go (1 hunks)
  • test/e2e/major_upgrade_v2.go (1 hunks)
  • test/e2e/major_upgrade_v3.go (1 hunks)
  • test/e2e/minor_version_compatibility.go (2 hunks)
  • test/e2e/simple.go (1 hunks)
  • test/e2e/testnet/testnet.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (4)
  • test/e2e/main.go
  • test/e2e/major_upgrade_v2.go
  • test/e2e/minor_version_compatibility.go
  • test/e2e/simple.go
🧰 Additional context used
🔇 Additional comments (10)
test/e2e/benchmark/benchmark.go (2)

15-16: LGTM: New import for Knuu package.

The addition of the Knuu package import is appropriate for the new functionality being introduced in this file.


18-20: LGTM: Time format constant added.

The addition of the timeFormat constant is a good practice. It ensures consistency in time formatting across the package and improves maintainability.

test/e2e/testnet/testnet.go (2)

33-39: Excellent addition of the Options struct!

The introduction of the Options struct is a great improvement. It enhances the extensibility and readability of the New function by grouping related parameters. This change will make it easier to add new options in the future without modifying the function signature.


33-49: Overall: Significant improvement in package design

The changes introduced in this PR represent a substantial improvement in the testnet package's design. The new Options struct and the updated New function signature enhance flexibility and extensibility while maintaining the core functionality.

To ensure a smooth transition, please verify that all other parts of the codebase that use this package have been updated to work with the new API. Run the following script to check for any remaining usages of the old New function signature:

If any results are found, they will need to be updated to use the new Options struct.

✅ Verification successful

Verification Successful: No Remaining Old New Function Usages

All usages of the old New function signature have been successfully updated. No remaining instances of the outdated New function are found in the codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for old New function usage
rg --type go 'New\s*\(\s*ctx\s*,\s*name\s*,\s*seed\s*,\s*grafana\s*,\s*chainID\s*,\s*genesisModifiers' --glob '!test/e2e/testnet/testnet.go'

Length of output: 142


Script:

#!/bin/bash
# Search for any usage of the New function in Go files excluding testnet.go
rg --type go 'New\s*\(' --glob '!test/e2e/testnet/testnet.go'

Length of output: 8982

test/e2e/major_upgrade_v3.go (6)

13-13: Importing the knuu package

The import statement for github.com/celestiaorg/knuu/pkg/knuu correctly adds the necessary package for Knuu integration.


18-21: Initialization of new variables for test configuration

The addition of testName, numNodes, and the change of upgradeHeightV3 to int64(10) enhances the configurability of the test. This allows for more flexibility in test scenarios.


27-31: Initialization of Knuu instance with context and options

The Knuu instance kn is properly initialized with the context and options, including Scope and ProxyEnabled. Error handling after initialization ensures robustness.


33-34: Handling stop signals and logging Knuu initialization

Using kn.HandleStopSignal(ctx) allows the application to gracefully handle termination signals. Logging the initialization of Knuu with scope enhances observability.


37-41: Updating testnet.New to use testnet.Options struct

Refactoring the testnet.New function to use the testnet.Options struct improves code clarity and future maintainability. Passing Knuu: kn integrates the Knuu instance into the testnet setup effectively.


20-20: Verify the change of upgradeHeightV3 from 20 to 10

The upgradeHeightV3 has been modified from int64(20) to int64(10). Please ensure that this change aligns with your testing requirements and that the upgrade occurs at the intended block height.

To confirm that the upgrade height is correctly set and does not affect other tests, you can verify its usage:

✅ Verification successful

upgradeHeightV3 successfully updated to 10

The change from int64(20) to int64(10) has been verified across the codebase. No remaining instances of upgradeHeightV3 set to int64(20) were found.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that `upgradeHeightV3` is correctly set to 10 and is used appropriately.

# Test: Search for the usage of `upgradeHeightV3` in the codebase.
# Expect: Occurrences where `upgradeHeightV3` is set to 10.

rg --type go 'upgradeHeightV3' -A 5

Length of output: 712


Script:

#!/bin/bash
# Description: Check for any occurrences where `upgradeHeightV3` is still set to 20.

# Test: Search for assignments of `upgradeHeightV3` to `int64(20)`.
# Expect: No matches should be found.

rg --type go 'upgradeHeightV3\s*=\s*int64\(20\)'

Length of output: 50

Comment on lines +28 to +43
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

identifier := fmt.Sprintf("%s_%s", name, time.Now().Format(timeFormat))
kn, err := knuu.New(ctx, knuu.Options{
Scope: identifier,
ProxyEnabled: true,
})
if err != nil {
return nil, err
}

// context.Background() is used to allow the stopSignal to be functioning even after this function returns
kn.HandleStopSignal(context.Background())

log.Printf("Knuu initialized with scope %s", kn.Scope)
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Remove deferred context cancellation and LGTM for Knuu initialization.

The Knuu initialization and setup look good. However, as noted in a previous review, the deferred context cancellation on line 29 should be removed to prevent potential premature termination of Knuu operations.

 ctx, cancel := context.WithCancel(context.Background())
-defer cancel()

The rest of the changes, including the unique identifier generation, Knuu initialization, and stop signal handling, are well-implemented and provide good observability with the added log statement.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
identifier := fmt.Sprintf("%s_%s", name, time.Now().Format(timeFormat))
kn, err := knuu.New(ctx, knuu.Options{
Scope: identifier,
ProxyEnabled: true,
})
if err != nil {
return nil, err
}
// context.Background() is used to allow the stopSignal to be functioning even after this function returns
kn.HandleStopSignal(context.Background())
log.Printf("Knuu initialized with scope %s", kn.Scope)
ctx, cancel := context.WithCancel(context.Background())
identifier := fmt.Sprintf("%s_%s", name, time.Now().Format(timeFormat))
kn, err := knuu.New(ctx, knuu.Options{
Scope: identifier,
ProxyEnabled: true,
})
if err != nil {
return nil, err
}
// context.Background() is used to allow the stopSignal to be functioning even after this function returns
kn.HandleStopSignal(context.Background())
log.Printf("Knuu initialized with scope %s", kn.Scope)

ctx, cancel := context.WithCancel(context.Background())
defer cancel()

identifier := fmt.Sprintf("%s_%s", testName, time.Now().Format(timeFormat))
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Undefined variable timeFormat in identifier formatting

The variable timeFormat used in time.Now().Format(timeFormat) is not defined within the provided scope. This will result in a compilation error due to the undefined variable.

To fix this issue, define timeFormat as a constant at the appropriate scope. You can add the following line at the beginning of the function or file:

const timeFormat = "2006-01-02_15-04-05" // Define the desired time format

This defines timeFormat with the standard layout for formatting time in Go.

logger.Println("Creating testnet")
testNet, err := testnet.New(ctx, "MajorUpgradeToV3", seed, nil, "test")
testNet, err := testnet.New(testnet.Options{
Seed: seed,
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Undefined variable seed in testnet.New options

The variable seed used in testnet.Options{ Seed: seed, ... } is not defined within the provided code. This will lead to a compilation error.

Ensure that seed is defined before it is used. For example, you can generate a seed using the current time:

seed := time.Now().UnixNano()

Add this definition before the testnet.New call to provide a seed value for the testnet initialization.


func New(opts Options) (*Testnet, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I prefer the use of Options for arguments to a constructor which are in fact optional. All fields here can have working defaults except for the Knuu instance which is mandatory thus I'd prefer

Suggested change
func New(opts Options) (*Testnet, error) {
func New(knuu *knuu.Knuu, opts Options) (*Testnet, error) {

so now it's more explicit or better still if you go with

type Option func (*Testnet) 

func WithSeed(seed int64) Option {
    return func (t *Testnet) {
        t.seed = seed
    }
}

func New(knuu *knuu.Knuu, options Option...) *Testnet

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants