-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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(server/v2): Add system-test for store's command #21357
Conversation
📝 WalkthroughWalkthroughThe recent changes introduce enhanced testing capabilities for a blockchain application, focusing on CLI command execution and snapshot management. A new method for running commands with arguments was added, along with comprehensive system tests for snapshot operations such as creation, deletion, and restoration. Additionally, the ability to start and stop individual validator nodes was integrated, allowing for improved control during testing scenarios. Changes
Sequence Diagram(s)sequenceDiagram
participant CLIWrapper
participant SystemUnderTest
participant SnapshotManager
CLIWrapper->>SystemUnderTest: RunCommandWithArgs(args)
SystemUnderTest->>CLIWrapper: Execute command
alt Command Success
CLIWrapper-->>SystemUnderTest: Return output
SystemUnderTest->>SnapshotManager: Manage snapshot operations
SnapshotManager->>SnapshotManager: Create, List, Delete, Load snapshots
else Command Failure
CLIWrapper-->>SystemUnderTest: Return error output
end
Assessment against linked issues
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
Documentation and Community
|
There was a problem hiding this 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.yml
Review profile: CHILL
Files selected for processing (3)
- tests/systemtests/cli.go (1 hunks)
- tests/systemtests/snapshots_test.go (1 hunks)
- tests/systemtests/system.go (1 hunks)
Additional context used
Path-based instructions (3)
tests/systemtests/snapshots_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/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"
Additional comments not posted (15)
tests/systemtests/snapshots_test.go (12)
16-26
: Ensure chain is properly reset and started.The chain is reset and started before performing snapshot operations, which is good practice to ensure a clean test environment.
34-37
: Verify snapshot export operation.The test correctly verifies the snapshot export operation by checking for the presence of a success message and the existence of the snapshot directory.
39-41
: Check snapshot list operation.The snapshot list operation is verified by checking for the expected height in the output.
43-46
: Validate snapshot dump operation.The test ensures that the snapshot dump operation is successful by checking for the existence of the output file.
48-50
: Confirm snapshot delete operation.The snapshot delete operation is validated by confirming the absence of the snapshot directory.
52-54
: Verify snapshot load operation.The snapshot load operation is verified by checking for the re-creation of the snapshot directory.
58-62
: Ensure databases are removed before restore.The test correctly removes the application and state sync databases before attempting to restore from a snapshot, ensuring a clean state.
64-66
: Validate snapshot restore operation.The snapshot restore operation is confirmed by checking the existence of the restored databases.
68-69
: Restart node after snapshot operations.The node is restarted after completing snapshot operations, which is necessary to ensure the system is back to a running state.
72-82
: Ensure chain is properly reset and started for prune test.The chain is reset and started before performing the prune operation, ensuring a clean test environment.
90-92
: Verify prune operation.The prune operation is validated by checking for a success message in the output.
94-95
: Restart node after prune operation.The node is restarted after the prune operation, ensuring the system is back to a running state.
tests/systemtests/cli.go (1)
172-180
: Well-implemented method for running CLI commands.The
RunCommandWithArgs
method is correctly implemented as a wrapper around therun
method, providing a clear interface for executing CLI commands with arguments.tests/systemtests/system.go (2)
334-351
: Ensure error handling for stopping nodes.The
StopSingleNode
method is well-implemented for stopping a single validator node. Ensure that the method is used in contexts where stopping the first node is appropriate, as it assumes the first PID corresponds to the node to be stopped.
353-362
: Correct implementation for starting a single node.The
StartSingleNode
method is correctly implemented, executing the command to start a node and ensuring no errors occur during the process.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice job!!
tests/systemtests/snapshots_test.go
Outdated
"github.com/stretchr/testify/require" | ||
) | ||
|
||
const nodeDir = "./testnet/node0/simdv2" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this wont work with v1, we should make sure it works with both
There was a problem hiding this 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.yml
Review profile: CHILL
Files selected for processing (2)
- tests/systemtests/snapshots_test.go (1 hunks)
- tests/systemtests/system.go (1 hunks)
Files skipped from review as they are similar to previous changes (2)
- tests/systemtests/snapshots_test.go
- tests/systemtests/system.go
There was a problem hiding this 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.yml
Review profile: CHILL
Files selected for processing (1)
- tests/systemtests/snapshots_test.go (1 hunks)
Files skipped from review as they are similar to previous changes (1)
- tests/systemtests/snapshots_test.go
tests/systemtests/cli.go
Outdated
// RunCommandWithArgs use for run cli command, not tx | ||
func (c CLIWrapper) RunCommandWithArgs(args ...string) string { | ||
c.t.Helper() | ||
execOutput, ok := c.run(args) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It always returns the execOutput here, shouldn't it return an error if not okay? Or is that expected that ok is ignored?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think should ignore it with the local command. execOutput
already returns err if cmd failed, handler by run
func.
tests/systemtests/system.go
Outdated
} | ||
|
||
// Kill the 1st node | ||
return p.Kill() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really want to kill it that way? This sends iirc a SIGKILL, we may want to stop the node more gracefully with SIGTERM
@@ -0,0 +1,121 @@ | |||
//go:build system_test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As the commands are really different between simapp and simapp v2, shall we not split the test in two tests?
The multiple if conditions will make it harder to maintain.
We can then just skip the tests when we run with COSMOS_BUILD_OPTIONS v2 and vice versa
Wdyt? cc @tac0turtle
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we update the prefix, most diff is that v2 has store
prefix and v1 has snapshots
?
There was a problem hiding this 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.yml
Review profile: CHILL
Files selected for processing (2)
- tests/systemtests/cli.go (1 hunks)
- tests/systemtests/system.go (1 hunks)
Files skipped from review as they are similar to previous changes (2)
- tests/systemtests/cli.go
- tests/systemtests/system.go
There was a problem hiding this 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.yml
Review profile: CHILL
Files selected for processing (1)
- tests/systemtests/system.go (1 hunks)
Files skipped from review as they are similar to previous changes (1)
- tests/systemtests/system.go
There was a problem hiding this 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.yml
Review profile: CHILL
Files selected for processing (2)
- tests/systemtests/cli.go (1 hunks)
- tests/systemtests/system.go (1 hunks)
Files skipped from review as they are similar to previous changes (2)
- tests/systemtests/cli.go
- tests/systemtests/system.go
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 4
Review details
Configuration used: .coderabbit.yml
Review profile: CHILL
Files selected for processing (4)
- tests/systemtests/Makefile (1 hunks)
- tests/systemtests/snapshots_v1_test.go (1 hunks)
- tests/systemtests/snapshots_v2_test.go (1 hunks)
- tests/systemtests/system.go (2 hunks)
Files skipped from review as they are similar to previous changes (1)
- tests/systemtests/system.go
Additional context used
Path-based instructions (3)
tests/systemtests/Makefile (1)
Pattern
tests/**/*
: "Assess the integration and e2e test code assessing sufficient code coverage for the changes associated in the pull request"tests/systemtests/snapshots_v1_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/snapshots_v2_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 not posted (1)
tests/systemtests/Makefile (1)
8-8
: LGTM!The dynamic construction of the
-tags
option based on the presence ofv2
in theCOSMOS_BUILD_OPTIONS
variable enhances the flexibility of the test command.The code changes are approved.
func TestSnapshots(t *testing.T) { | ||
sut.ResetChain(t) | ||
cli := NewCLIWrapper(t, sut, verbose) | ||
// add genesis account with some tokens | ||
account1Addr := cli.AddKey("account1") | ||
sut.ModifyGenesisCLI(t, | ||
[]string{"genesis", "add-genesis-account", account1Addr, "10000000stake"}, | ||
) | ||
|
||
sut.StartChain(t) | ||
nodeDir = filepath.Join(WorkDir, "testnet", "node0", "simd") | ||
|
||
// Wait for chain produce some blocks | ||
time.Sleep(time.Second * 10) | ||
// Stop 1 node | ||
err := sut.StopSingleNode() | ||
require.NoError(t, err) | ||
time.Sleep(time.Second * 5) | ||
|
||
// export snapshot at height 5 | ||
res := cli.RunCommandWithArgs("snapshots", "export", "--height=5", fmt.Sprintf("--home=%s", nodeDir)) | ||
require.Contains(t, res, "Snapshot created at height 5") | ||
require.DirExists(t, fmt.Sprintf("%s/data/snapshots/5/3", nodeDir)) | ||
|
||
// Check snapshots list | ||
res = cli.RunCommandWithArgs("snapshots", "list", fmt.Sprintf("--home=%s", nodeDir)) | ||
require.Contains(t, res, "height: 5") | ||
|
||
// Dump snapshot | ||
res = cli.RunCommandWithArgs("snapshots", "dump", "5", "3", fmt.Sprintf("--home=%s", nodeDir), fmt.Sprintf("--output=%s/5-3.tar.gz", nodeDir)) | ||
// Check if output file exist | ||
require.FileExists(t, fmt.Sprintf("%s/5-3.tar.gz", nodeDir)) | ||
|
||
// Delete snapshots | ||
res = cli.RunCommandWithArgs("snapshots", "delete", "5", "3", fmt.Sprintf("--home=%s", nodeDir)) | ||
require.NoDirExists(t, fmt.Sprintf("%s/data/snapshots/5/3", nodeDir)) | ||
|
||
// Load snapshot from file | ||
res = cli.RunCommandWithArgs("snapshots", "load", fmt.Sprintf("%s/5-3.tar.gz", nodeDir), fmt.Sprintf("--home=%s", nodeDir)) | ||
require.DirExists(t, fmt.Sprintf("%s/data/snapshots/5/3", nodeDir)) | ||
|
||
// Restore from snapshots | ||
|
||
// Remove database | ||
err = os.RemoveAll(fmt.Sprintf("%s/data/application.db", nodeDir)) | ||
require.NoError(t, err) | ||
|
||
res = cli.RunCommandWithArgs("snapshots", "restore", "5", "3", fmt.Sprintf("--home=%s", nodeDir)) | ||
require.DirExists(t, fmt.Sprintf("%s/data/application.db", nodeDir)) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider using a more reliable synchronization mechanism.
The hardcoded sleep durations might make the tests flaky. Consider using a more reliable synchronization mechanism, such as waiting for a specific log message or event, to ensure the chain has produced the required blocks or the node has stopped.
func TestPrune(t *testing.T) { | ||
sut.ResetChain(t) | ||
cli := NewCLIWrapper(t, sut, verbose) | ||
// add genesis account with some tokens | ||
account1Addr := cli.AddKey("account1") | ||
sut.ModifyGenesisCLI(t, | ||
[]string{"genesis", "add-genesis-account", account1Addr, "10000000stake"}, | ||
) | ||
|
||
sut.StartChain(t) | ||
nodeDir = filepath.Join(WorkDir, "testnet", "node0", "simd") | ||
|
||
// Wait for chain produce some blocks | ||
time.Sleep(time.Second * 10) | ||
// Stop 1 node | ||
err := sut.StopSingleNode() | ||
require.NoError(t, err) | ||
time.Sleep(time.Second) | ||
|
||
// prune | ||
res := cli.RunCommandWithArgs("prune", "everything", fmt.Sprintf("--home=%s", nodeDir)) | ||
require.Contains(t, res, "successfully pruned the application root multi stores") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider using a more reliable synchronization mechanism.
The hardcoded sleep durations might make the tests flaky. Consider using a more reliable synchronization mechanism, such as waiting for a specific log message or event, to ensure the chain has produced the required blocks or the node has stopped.
func TestSnapshots(t *testing.T) { | ||
fmt.Println("TestSnapshots") | ||
sut.ResetChain(t) | ||
cli := NewCLIWrapper(t, sut, verbose) | ||
// add genesis account with some tokens | ||
account1Addr := cli.AddKey("account1") | ||
sut.ModifyGenesisCLI(t, | ||
[]string{"genesis", "add-genesis-account", account1Addr, "10000000stake"}, | ||
) | ||
|
||
sut.StartChain(t) | ||
nodeDir = filepath.Join(WorkDir, "testnet", "node0", "simdv2") | ||
|
||
// Wait for chain produce some blocks | ||
time.Sleep(time.Second * 10) | ||
// Stop 1 node | ||
err := sut.StopSingleNode() | ||
require.NoError(t, err) | ||
time.Sleep(time.Second * 5) | ||
|
||
// export snapshot at height 5 | ||
res := cli.RunCommandWithArgs("store", "export", "--height=5", fmt.Sprintf("--home=%s", nodeDir)) | ||
require.Contains(t, res, "Snapshot created at height 5") | ||
require.DirExists(t, fmt.Sprintf("%s/data/snapshots/5/3", nodeDir)) | ||
|
||
// Check snapshots list | ||
res = cli.RunCommandWithArgs("store", "list", fmt.Sprintf("--home=%s", nodeDir)) | ||
require.Contains(t, res, "height: 5") | ||
|
||
// Dump snapshot | ||
res = cli.RunCommandWithArgs("store", "dump", "5", "3", fmt.Sprintf("--home=%s", nodeDir), fmt.Sprintf("--output=%s/5-3.tar.gz", nodeDir)) | ||
// Check if output file exist | ||
require.FileExists(t, fmt.Sprintf("%s/5-3.tar.gz", nodeDir)) | ||
|
||
// Delete snapshots | ||
res = cli.RunCommandWithArgs("store", "delete", "5", "3", fmt.Sprintf("--home=%s", nodeDir)) | ||
require.NoDirExists(t, fmt.Sprintf("%s/data/snapshots/5/3", nodeDir)) | ||
|
||
// Load snapshot from file | ||
res = cli.RunCommandWithArgs("store", "load", fmt.Sprintf("%s/5-3.tar.gz", nodeDir), fmt.Sprintf("--home=%s", nodeDir)) | ||
require.DirExists(t, fmt.Sprintf("%s/data/snapshots/5/3", nodeDir)) | ||
|
||
// Restore from snapshots | ||
|
||
// Remove database | ||
err = os.RemoveAll(fmt.Sprintf("%s/data/application.db", nodeDir)) | ||
require.NoError(t, err) | ||
err = os.RemoveAll(fmt.Sprintf("%s/data/ss", nodeDir)) | ||
require.NoError(t, err) | ||
|
||
res = cli.RunCommandWithArgs("store", "restore", "5", "3", fmt.Sprintf("--home=%s", nodeDir)) | ||
require.DirExists(t, fmt.Sprintf("%s/data/application.db", nodeDir)) | ||
require.DirExists(t, fmt.Sprintf("%s/data/ss", nodeDir)) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider using a more reliable synchronization mechanism.
The hardcoded sleep durations might make the tests flaky. Consider using a more reliable synchronization mechanism, such as waiting for a specific log message or event, to ensure the chain has produced the required blocks or the node has stopped.
func TestPrune(t *testing.T) { | ||
sut.ResetChain(t) | ||
cli := NewCLIWrapper(t, sut, verbose) | ||
// add genesis account with some tokens | ||
account1Addr := cli.AddKey("account1") | ||
sut.ModifyGenesisCLI(t, | ||
[]string{"genesis", "add-genesis-account", account1Addr, "10000000stake"}, | ||
) | ||
|
||
sut.StartChain(t) | ||
nodeDir = filepath.Join(WorkDir, "testnet", "node0", "simdv2") | ||
|
||
// Wait for chain produce some blocks | ||
time.Sleep(time.Second * 10) | ||
// Stop 1 node | ||
err := sut.StopSingleNode() | ||
require.NoError(t, err) | ||
time.Sleep(time.Second) | ||
|
||
// prune | ||
res := cli.RunCommandWithArgs("store", "prune", "--keep-recent=1", fmt.Sprintf("--home=%s", nodeDir)) | ||
require.Contains(t, res, "successfully pruned the application root multi stores") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider using a more reliable synchronization mechanism.
The hardcoded sleep durations might make the tests flaky. Consider using a more reliable synchronization mechanism, such as waiting for a specific log message or event, to ensure the chain has produced the required blocks or the node has stopped.
There was a problem hiding this 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.yml
Review profile: CHILL
Files selected for processing (1)
- tests/systemtests/system.go (2 hunks)
Files skipped from review as they are similar to previous changes (1)
- tests/systemtests/system.go
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
Quality Gate passed for 'Cosmos SDK - Store'Issues Measures |
systemtest v1 failing at |
This does not look related to your changes. I have triggered a re-run |
Adding backport label for system tests backport |
Co-authored-by: Alexander Peters <[email protected]> (cherry picked from commit ef8e2d4) # Conflicts: # store/snapshots/manager.go # store/v2/snapshots/manager.go # tests/systemtests/system.go
#22093) Co-authored-by: Hieu Vu <[email protected]> Co-authored-by: Julien Robert <[email protected]>
Description
Closes: #21184
Add system-test for
snapshots
&prune
Currently v1 TestSnapshots failed because of #21404
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...
!
in the type prefix if API or client breaking changeCHANGELOG.md
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...
Summary by CodeRabbit
Summary by CodeRabbit
New Features
Bug Fixes