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: reduce the bittwister tests #384

Merged
merged 7 commits into from
Jun 7, 2024

Conversation

mojtaba-esk
Copy link
Contributor

@mojtaba-esk mojtaba-esk commented May 29, 2024

Closes #381

Summary by CodeRabbit

  • Refactor

    • Updated test cases for bandwidth, packet loss, latency, and jitter to reflect new values and remove outdated scenarios.
    • Refactored test functions to use a test suite structure for improved organization and maintainability.
    • Enhanced instance running state check logic to ensure more reliable instance status verification.
  • Chores

    • Added setup and teardown logic for test suites to streamline test execution.
    • Updated method signatures to include context parameters for better context handling during cleanup operations.

@mojtaba-esk mojtaba-esk requested a review from a team May 29, 2024 10:06
@mojtaba-esk mojtaba-esk self-assigned this May 29, 2024
@MSevey
Copy link
Member

MSevey commented May 29, 2024

We should merge this PR in #401 so that we can run the tests on this PR.

@MSevey
Copy link
Member

MSevey commented May 29, 2024

I was looking at the runtimes of the bittwister tests in some recent CI and I think we should restructure these tests even more to save more CI time.

Currently the test structure is generally the following:

func TestX() {
   t.Parallel()
   // testSetUp
   // define test cases
   // run test cases
}

This structure runs the the high level tests in parallel but runs the test cases sequentially. Normally this is ideal because the test setup is the bulk of the test time and the test cases are not very time intensive.

However for these tests it is the reverse, in that the test cases are where the bulk of the time is spent.

So we could structure them like this:

func TestX() {
    t.Parallel()
    // Define test cases
    // run testcases
    t.Run(
        t.Parallel()
        // Test setup
    )
}

This is going to duplicate the time of test setup up, but enables running each test case in parallel in addition to running each high level test in parallel.
Running locally the setup for the packetloss test for example is 7s. Adding 7s to the minimum runtime in order to run the test cases in parallel is definitely worth it imo.

It is worth noting though that this change is optimizing for local CI as the github runners only have a single core I believe so tests never run in parallel anyways. But as it would only increase the overall run time by n*setupTime and we are limiting each test to 3 cases based on my previous recommendation, I think it is worth it.


POC with the Jitter test locally.
Running the tests as is

--- PASS: TestBittwister_Jitter (194.64s)
    --- PASS: TestBittwister_Jitter/Max_Jitter_10ms (2.85s)
    --- PASS: TestBittwister_Jitter/Max_Jitter_20ms (3.32s)
    --- PASS: TestBittwister_Jitter/Max_Jitter_50ms (4.09s)
    --- PASS: TestBittwister_Jitter/Max_Jitter_100ms (5.40s)
    --- PASS: TestBittwister_Jitter/Max_Jitter_200ms (7.63s)
    --- PASS: TestBittwister_Jitter/Max_Jitter_500ms (14.58s)
    --- PASS: TestBittwister_Jitter/Max_Jitter_1s (28.57s)
    --- PASS: TestBittwister_Jitter/Max_Jitter_2s (55.90s)
    --- PASS: TestBittwister_Jitter/Max_Jitter_3s (64.81s)
PASS
ok      github.com/celestiaorg/knuu/e2e/bittwister      213.875s

running the tests with the new parallel set up

--- PASS: TestBittwister_Jitter (0.00s)
    --- PASS: TestBittwister_Jitter/Max_Jitter_10ms (14.93s)
    --- PASS: TestBittwister_Jitter/Max_Jitter_20ms (17.49s)
    --- PASS: TestBittwister_Jitter/Max_Jitter_100ms (18.31s)
    --- PASS: TestBittwister_Jitter/Max_Jitter_50ms (18.89s)
    --- PASS: TestBittwister_Jitter/Max_Jitter_500ms (22.41s)
    --- PASS: TestBittwister_Jitter/Max_Jitter_200ms (16.94s)
    --- PASS: TestBittwister_Jitter/Max_Jitter_1s (40.43s)
    --- PASS: TestBittwister_Jitter/Max_Jitter_2s (60.07s)
    --- PASS: TestBittwister_Jitter/Max_Jitter_3s (74.52s)
PASS
ok      github.com/celestiaorg/knuu/e2e/bittwister      91.493s

Base automatically changed from mojtaba/remove-100_packetloss-test to main May 30, 2024 06:48
Copy link
Contributor

coderabbitai bot commented May 30, 2024

Walkthrough

The changes primarily focus on optimizing and refactoring the BitTwister tests by reducing the number of test cases for bandwidth, packet loss, latency, and jitter to expedite the testing process. Additionally, the tests have been restructured to use a test suite for better organization and maintenance. Context handling and cleanup logic have been improved across several files to enhance robustness.

Changes

Files and Paths Change Summaries
e2e/basic/bittwister_test.go Reordered and updated test scenarios for bandwidth, packet loss, latency, and jitter. Removed redundant test cases. Updated tolerance percentages.
e2e/bittwister/bittwister_test.go Refactored to use a test suite structure, updated method calls, modified test data generation, and improved cleanup logic.
e2e/bittwister/suite_setup_test.go Added a test suite setup for BitTwister tests, including setup and teardown methods.
pkg/instance/instance.go Enhanced WaitInstanceIsRunning method with additional running state checks before timeout.
pkg/knuu/knuu.go Updated HandleStopSignal to take ctx context.Context and modified CleanUp call accordingly.
pkg/knuu/knuu_old.go Updated HandleStopSignal call in InitializeWithScope to include context.Background().

Assessment against linked issues

Objective Addressed Explanation
Reduce the number of BitTwister tests (Issue #381)

Poem

In the land of code, where tests do dance,
A rabbit hopped with great expanse.
BitTwister tests, now fewer in line,
Bandwidth and jitter, all refined.
With context clear and cleanup bright,
Our tests now run both swift and light.
🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

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

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between fc126f1 and 6039ead.

Files selected for processing (1)
  • e2e/basic/bittwister_test.go (4 hunks)
Additional comments not posted (1)
e2e/basic/bittwister_test.go (1)

396-396: The changes in the jitter tests align well with the PR objectives.

The modifications to the jitter tests are appropriate and align with the objectives of reducing the number of tests while maintaining essential coverage.

e2e/basic/bittwister_test.go Outdated Show resolved Hide resolved
e2e/basic/bittwister_test.go Outdated Show resolved Hide resolved
e2e/basic/bittwister_test.go Outdated Show resolved Hide resolved
@mojtaba-esk mojtaba-esk requested a review from MSevey May 30, 2024 09:57
Copy link
Member

@MSevey MSevey left a comment

Choose a reason for hiding this comment

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

What are your thoughts on adding the random third test case to help fuzz things? I think this is a value testing strategy.

Also what are your thoughts on the restructure to speed up the tests locally?

@mojtaba-esk
Copy link
Contributor Author

mojtaba-esk commented May 30, 2024

What are your thoughts on adding the random third test case to help fuzz things? I think this is a value testing strategy.

I think that adds a value, however it is tricky to choose the right tolerance. We either have to keep it a large number for most tests or find a formula to calculate it to let some room for the measurement accuracy errors.

Also what are your thoughts on the restructure to speed up the tests locally?

 t.Run(
        t.Parallel()
        // Test setup
    )

if we wanna run those tests in parallel we need to create or clone dedicated instances per test case because currently, bittwister tests uses the same instance to apply traffic shaping.

tty47
tty47 previously approved these changes Jun 3, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 6039ead and 4abfe7e.

Files selected for processing (1)
  • e2e/basic/bittwister_test.go (15 hunks)
Files skipped from review as they are similar to previous changes (1)
  • e2e/basic/bittwister_test.go

tty47
tty47 previously approved these changes Jun 5, 2024
smuu
smuu previously approved these changes Jun 5, 2024
@mojtaba-esk mojtaba-esk enabled auto-merge June 5, 2024 08:28
@mojtaba-esk mojtaba-esk dismissed stale reviews from smuu and tty47 via 902361c June 5, 2024 08:30
@mojtaba-esk mojtaba-esk requested review from smuu and tty47 June 5, 2024 08:31
tty47
tty47 previously approved these changes Jun 5, 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: 4

Outside diff range and nitpick comments (1)
e2e/bittwister/bittwister_test.go (1)

Line range hint 21-115: Well-structured test function with dynamic test case generation. Consider adding more detailed comments explaining the choice of random values and their impact on test robustness.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 4abfe7e and 8517339.

Files selected for processing (5)
  • e2e/bittwister/bittwister_test.go (4 hunks)
  • e2e/bittwister/suite_setup_test.go (1 hunks)
  • pkg/instance/instance.go (1 hunks)
  • pkg/knuu/knuu.go (1 hunks)
  • pkg/knuu/knuu_old.go (1 hunks)
Additional comments not posted (6)
e2e/bittwister/suite_setup_test.go (3)

13-16: The Suite struct is well-defined and appropriate for encapsulating the test suite's state.


29-37: The cleanup process in TearDownSuite is robust, ensuring resources are properly released even if errors occur.


39-41: Standard and correct usage of the suite.Run to execute the test suite.

pkg/knuu/knuu_old.go (1)

99-99: Ensure the use of context.Background() in HandleStopSignal is justified and documented, especially since this file is for backward compatibility.

Verification successful

The usage of context.Background() in the deprecated files pkg/knuu/knuu_old.go, pkg/knuu/preloader_old.go, and pkg/knuu/instance_old.go is justified for maintaining backward compatibility. It ensures that these deprecated functions remain functional without introducing new dependencies or complexities.

  • pkg/knuu/knuu_old.go
  • pkg/knuu/preloader_old.go
  • pkg/knuu/instance_old.go

Consider documenting this rationale to provide clarity for future maintainers.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the usage of context.Background() in deprecated files.

# Test: Search for the usage of context.Background() in deprecated files. Expect: Justified usage.
rg --type go $'context.Background()' --files-with-matches | xargs grep -l 'This file is deprecated'

Length of output: 172



Script:

#!/bin/bash
# Extract code snippets around the usage of context.Background() in the identified files.

# Extract 5 lines before and after the usage of context.Background() in pkg/knuu/knuu_old.go
echo "pkg/knuu/knuu_old.go:"
rg -C 5 'context.Background()' pkg/knuu/knuu_old.go

# Extract 5 lines before and after the usage of context.Background() in pkg/knuu/preloader_old.go
echo "pkg/knuu/preloader_old.go:"
rg -C 5 'context.Background()' pkg/knuu/preloader_old.go

# Extract 5 lines before and after the usage of context.Background() in pkg/knuu/instance_old.go
echo "pkg/knuu/instance_old.go:"
rg -C 5 'context.Background()' pkg/knuu/instance_old.go

Length of output: 8265

pkg/knuu/knuu.go (1)

172-178: Excellent use of context in HandleStopSignal for better signal handling and resource cleanup.

pkg/instance/instance.go (1)

1094-1106: Refactor WaitInstanceIsRunning to improve reliability.

The changes in the WaitInstanceIsRunning method enhance the reliability by periodically checking the instance's state. This is a good practice in asynchronous operations. However, consider adding more detailed logging at each retry to improve traceability and debugging.

e2e/bittwister/suite_setup_test.go Show resolved Hide resolved
e2e/bittwister/bittwister_test.go Show resolved Hide resolved
e2e/bittwister/bittwister_test.go Show resolved Hide resolved
e2e/bittwister/bittwister_test.go Show resolved Hide resolved
Copy link
Member

@MSevey MSevey left a comment

Choose a reason for hiding this comment

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

lgtm, I updated the branch to pull in Jose's govuln fix.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 8517339 and 7de0ce5.

Files selected for processing (1)
  • pkg/knuu/knuu.go (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • pkg/knuu/knuu.go

@mojtaba-esk mojtaba-esk added this pull request to the merge queue Jun 7, 2024
Merged via the queue into main with commit 5b65065 Jun 7, 2024
10 of 11 checks passed
@mojtaba-esk mojtaba-esk deleted the mojtaba/reduce-bittwister-tests branch June 7, 2024 07:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Reduce the number of BitTwister tests
4 participants