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(systemtests): fix failing tests #22145

Merged
merged 4 commits into from
Oct 7, 2024

Conversation

alpe
Copy link
Contributor

@alpe alpe commented Oct 7, 2024

Description

Fixes system tests


Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • included the correct type prefix in the PR title, you can find examples of the prefixes below:
  • confirmed ! in the type prefix if API or client breaking change
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • reviewed "Files changed" and left comments if necessary
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • updated the relevant documentation or specification, including comments for documenting Go code
  • confirmed all CI checks have passed

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

Please see Pull Request Reviewer section in the contributing guide for more information on how to review a pull request.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic, API design and naming, documentation is accurate, tests and test coverage

Summary by CodeRabbit

  • New Features

    • Introduced a new method to count the number of nodes in the system.
    • Added a function for initializing testnet commands with a specified binary.
  • Bug Fixes

    • Enhanced error reporting in HTTP response status code assertions.
  • Tests

    • Improved test cases for querying node information and validator sets, including conditional checks and updated HTTP status code handling.
    • Updated versioning and conditions for the chain upgrade test.

Copy link
Contributor

coderabbitai bot commented Oct 7, 2024

📝 Walkthrough

Walkthrough

The pull request introduces several enhancements to the test suite for querying node information and validator sets within the cometbft_client_test.go file. Key changes include conditional checks in tests, improved error handling with HTTP status codes, and the addition of new methods in the SystemUnderTest struct. The test cases have been updated to reflect these changes, ensuring better robustness and clarity. Additionally, a new initializer function has been added to facilitate testnet command initialization, and modifications have been made to the upgrade test to align with versioning changes.

Changes

File Path Change Summary
tests/systemtests/cometbft_client_test.go Enhanced test cases for querying node information and validator sets; added conditional checks, HTTP status code handling, and renamed functions.
tests/systemtests/rest_cli.go Updated GetRequestWithHeaders to include response body in error messages for status code assertions.
tests/systemtests/system.go Added NodesCount() method to SystemUnderTest struct for retrieving the number of nodes.
tests/systemtests/testnet_init.go Introduced InitializerWithBinary function for creating SingleHostTestnetCmdInitializer instances.
tests/systemtests/upgrade_test.go Modified TestChainUpgrade to skip under certain conditions; updated version numbers and upgrade names.

Possibly related issues

Possibly related PRs

Suggested labels

C:server/v2, C:CLI, C:collections, C:orm, C:indexer/postgres, Type: CI, backport/v0.52.x

Suggested reviewers

  • julienrbrt
  • tac0turtle
  • sontrinh16

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 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.

@alpe alpe changed the title Fix tests chore (systemtests): fix failing tests Oct 7, 2024
@alpe alpe force-pushed the alex/system_TestQueryLatestValidatorSet branch from 9a47afa to 56cb095 Compare October 7, 2024 10:06
@julienrbrt julienrbrt changed the title chore (systemtests): fix failing tests test(systemtests): fix failing tests Oct 7, 2024
@alpe alpe marked this pull request as ready for review October 7, 2024 12:47
@alpe alpe requested a review from a team as a code owner October 7, 2024 12:47
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 (6)
tests/systemtests/rest_cli.go (1)

84-85: Approved: Enhanced error reporting with response body inclusion

This change improves the error reporting by including the response body when the status code doesn't match the expected value. This additional context will be valuable for debugging failing tests, which aligns well with the PR's objective of fixing failing system tests.

Consider truncating very large response bodies to avoid overwhelming error messages. You could implement this by adding a helper function to limit the response body to a reasonable length (e.g., 1000 characters) if it exceeds that limit. For example:

func truncateBody(body []byte, maxLen int) string {
	if len(body) <= maxLen {
		return string(body)
	}
	return string(body[:maxLen]) + "... (truncated)"
}

Then use it in the error message:

require.Equal(t, expCode, res.StatusCode, "status code should be %d, got: %d, %s", expCode, res.StatusCode, truncateBody(body, 1000))

This would ensure that the error messages remain informative without becoming excessively long.

tests/systemtests/upgrade_test.go (2)

20-22: LGTM. Consider creating a tracking issue for re-enabling the test.

The skip message clearly explains why the test is currently disabled. This prevents false negatives in the test suite.

To ensure this test doesn't remain skipped indefinitely, would you like me to create a GitHub issue to track the re-enabling of this test once the conditions are met?


Line range hint 1-124: Overall, the changes look good but require some follow-up actions.

The updates to version numbers and upgrade names are consistent with the new versioning scheme. However, to ensure the integrity of the test suite, please:

  1. Create a tracking issue for re-enabling this test once the conditions mentioned in the skip message are met.
  2. Verify the availability of the v0.52 binary as suggested in the review comments.
  3. Confirm the consistency of the upgrade name across the codebase, particularly in simapp/upgrades.go.

These steps will help maintain the reliability and effectiveness of the upgrade test.

tests/systemtests/system.go (1)

769-772: LGTM! Consider adding a brief comment.

The NodesCount() method is a well-implemented getter for the nodesCount field. It follows Go conventions and provides a clean way to access this information.

Consider adding a brief comment to explain the purpose of this method, for example:

// NodesCount returns the number of node instances currently in use by the system under test.
func (s *SystemUnderTest) NodesCount() int {
	return s.nodesCount
}
tests/systemtests/cometbft_client_test.go (2)

213-213: Ensure consistent acronym casing in function names

In Go, acronyms should be consistently capitalized. Consider renaming the function to TestValidatorSetByHeight_GRPCRESTGateway to accurately represent the acronyms GRPC and REST.


222-226: Consistent capitalization of acronyms in struct field names

Acronyms in struct field names should be fully capitalized. Rename expHttpCode to expHTTPCode to maintain consistent acronym casing.

📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 112e228 and 35ba6e1.

📒 Files selected for processing (5)
  • tests/systemtests/cometbft_client_test.go (6 hunks)
  • tests/systemtests/rest_cli.go (1 hunks)
  • tests/systemtests/system.go (1 hunks)
  • tests/systemtests/testnet_init.go (1 hunks)
  • tests/systemtests/upgrade_test.go (1 hunks)
🧰 Additional context used
📓 Path-based instructions (5)
tests/systemtests/cometbft_client_test.go (3)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern tests/**/*: "Assess the integration and e2e test code assessing sufficient code coverage for the changes associated in the pull request"


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

tests/systemtests/rest_cli.go (2)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern tests/**/*: "Assess the integration and e2e test code assessing sufficient code coverage for the changes associated in the pull request"

tests/systemtests/system.go (2)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern tests/**/*: "Assess the integration and e2e test code assessing sufficient code coverage for the changes associated in the pull request"

tests/systemtests/testnet_init.go (2)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern tests/**/*: "Assess the integration and e2e test code assessing sufficient code coverage for the changes associated in the pull request"

tests/systemtests/upgrade_test.go (3)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern tests/**/*: "Assess the integration and e2e test code assessing sufficient code coverage for the changes associated in the pull request"


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

🔇 Additional comments (9)
tests/systemtests/upgrade_test.go (3)

34-34: LGTM. Good practice to use the legacy binary for initialization.

Setting the testnet initializer with the legacy binary ensures consistency between initialization and execution. This is a good practice that helps prevent version mismatch issues.


41-41: Verify consistency of upgrade name across the codebase.

The update to the upgrade name aligns with the new versioning scheme. However, we should ensure that this name is consistent with the UpgradeName in simapp/upgrades.go as mentioned in the comment.

Let's verify the consistency of the upgrade name:

#!/bin/bash
# Description: Check if the upgrade name is consistent in simapp/upgrades.go

# Test: Search for the upgrade name in simapp/upgrades.go
grep -n "v052-to-v054" $(fd -t f -e go upgrades.go)
if [ $? -eq 0 ]; then
    echo "Upgrade name is consistent in simapp/upgrades.go"
else
    echo "Upgrade name is not found or inconsistent in simapp/upgrades.go"
fi

29-29: Verify the availability of v0.52 binary.

The update to use the v0.52 binary aligns with the new versioning scheme. However, we should ensure that this version is actually available and compatible with the test setup.

Let's verify the availability of the v0.52 binary:

tests/systemtests/testnet_init.go (2)

54-66: LGTM! Enhancement to testnet initialization.

The new InitializerWithBinary function is a valuable addition that allows for more flexible testnet initialization by specifying a custom binary. The implementation is clean, follows Go conventions, and correctly utilizes the existing NewSingleHostTestnetCmdInitializer constructor.


Line range hint 1-66: File Review: Enhancing testnet initialization capabilities

The addition of the InitializerWithBinary function is the only change in this file. It integrates seamlessly with the existing code and provides a valuable enhancement to the testnet initialization process. The implementation adheres to Go best practices and the Uber Go Style Guide.

As per the coding guidelines for tests/**/*, this change contributes to improving the test coverage by allowing more flexible initialization of the testnet, which can lead to more comprehensive system tests.

tests/systemtests/cometbft_client_test.go (4)

8-8: Correctly imported net/http package

The addition of the net/http import is necessary for referencing HTTP status codes like http.StatusBadRequest.


170-176: Enhanced error handling in tests

The use of GetRequestWithHeaders along with expected HTTP status codes improves the robustness of the tests by explicitly checking for expected error conditions.


235-241: Improved test validation with expected HTTP status codes

Including expHTTPCode in the test cases and using it in GetRequestWithHeaders enhances test accuracy by validating the expected HTTP responses.


320-320: Assertion on res.Code strengthens test checks

Adding assert.Equal(t, tc.expectedCode, res.Code) ensures that the response code matches the expected value, enhancing the test's effectiveness.

@@ -103,7 +108,7 @@ func TestQueryLatestValidatorSet(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, len(res.Validators), 2)

restRes := GetRequest(t, mustV(url.JoinPath(baseurl, "/cosmos/base/tendermint/v1beta1/validatorsets/latest?pagination.offset=0&pagination.limit=2")))
restRes := GetRequest(t, fmt.Sprintf("%s/cosmos/base/tendermint/v1beta1/validatorsets/latest?pagination.offset=%d&pagination.limit=%d", baseurl, 0, 2))
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Use net/url package to construct URLs safely

Constructing URLs using fmt.Sprintf may lead to issues if parameters contain special characters. Consider using the net/url package to properly encode query parameters and build the URL safely.

Refactor the URL construction as follows:

u, err := url.Parse(fmt.Sprintf("%s/cosmos/base/tendermint/v1beta1/validatorsets/latest", baseurl))
if err != nil {
    t.Fatal(err)
}
q := u.Query()
q.Set("pagination.offset", "0")
q.Set("pagination.limit", "2")
u.RawQuery = q.Encode()
restRes := GetRequest(t, u.String())

Comment on lines +86 to +89
if sut.NodesCount() < 2 {
t.Skip("not enough nodes")
return
}
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 redundant return statement after t.Skip()

After calling t.Skip("not enough nodes"), the test execution is halted, so the return statement on line 88 is unnecessary and can be removed.

Apply this diff to remove the unnecessary return:

 if sut.NodesCount() < 2 {
     t.Skip("not enough nodes")
-    return
 }
📝 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
if sut.NodesCount() < 2 {
t.Skip("not enough nodes")
return
}
if sut.NodesCount() < 2 {
t.Skip("not enough nodes")
}

@julienrbrt julienrbrt added the backport/v0.52.x PR scheduled for inclusion in the v0.52's next stable release label Oct 7, 2024
@@ -17,25 +17,28 @@ import (
)

func TestChainUpgrade(t *testing.T) {
// err> panic: failed to load latest version: failed to load store: initial version set to 22, but found earlier version 1 [cosmossdk.io/store@v1.1.1/rootmulti/store.go:256]
Copy link
Member

Choose a reason for hiding this comment

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

this probably needs to be reverted in the 0.52 backport

@julienrbrt julienrbrt added this pull request to the merge queue Oct 7, 2024
Merged via the queue into main with commit b33484a Oct 7, 2024
76 of 77 checks passed
@julienrbrt julienrbrt deleted the alex/system_TestQueryLatestValidatorSet branch October 7, 2024 13:24
mergify bot pushed a commit that referenced this pull request Oct 7, 2024
(cherry picked from commit b33484a)

# Conflicts:
#	tests/systemtests/cometbft_client_test.go
julienrbrt added a commit that referenced this pull request Oct 7, 2024
Co-authored-by: Alexander Peters <alpe@users.noreply.github.com>
Co-authored-by: Julien Robert <julien@rbrt.fr>
@coderabbitai coderabbitai bot mentioned this pull request Oct 28, 2024
12 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport/v0.52.x PR scheduled for inclusion in the v0.52's next stable release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants