Skip to content

Conversation

NumberFour8
Copy link
Contributor

@NumberFour8 NumberFour8 commented Sep 25, 2024

Follow-up to #6501

This PR repurposes Node 6 in E2E tests to send tickets with winning probability lowered to 10%. Node 7 has been discarded completely from tests.

Then several integration tests are added to test multiple different scenarios with relaying tickets with lowered winning probability.

This PR repurposes Node #6 and Node #7 in E2E tests to send tickets with winning probability lowered to 10%.
Then several integration tests are added to test multiple different scenarios with relaying tickets with lowered winning probability.
@NumberFour8 NumberFour8 added this to the 2.2.0-rc.1 milestone Sep 25, 2024
@NumberFour8 NumberFour8 self-assigned this Sep 25, 2024
@github-actions github-actions bot added testing Related to tests crate:hoprd labels Sep 25, 2024
Copy link
Contributor

coderabbitai bot commented Sep 25, 2024

📝 Walkthrough
📝 Walkthrough

Walkthrough

This pull request modifies the tests/conftest.py file by removing unused functionality, updating function parameters, and introducing a new command execution utility. The changes include renaming a function to better reflect its purpose, adjusting timeouts for node readiness checks, and commenting out functionality related to an obsolete network variable. Additionally, the .github/workflows/tests.yaml file is updated to include new test suites and improve the setup process for Google Cloud SDK. A new test file tests/test_redeeming.py is introduced, containing asynchronous tests for ticket redemption and aggregation functionalities.

Changes

File Path Change Summary
tests/conftest.py Commented out the NETWORK2 variable; updated anvil_state_file parameters to use NETWORK1 and a new configuration file; renamed nodes_with_different_network to nodes_with_lower_outgoing_win_prob; removed check_socket function; added run_hopli_cmd function; modified timeouts in shared_nodes_bringup and encapsulated node readiness logic in is_node_ready.
.github/workflows/tests.yaml Added step to set up Google Cloud SDK; expanded job matrix in tests-smoke to include new test suites; modified gcloud storage rsync command to use --recursive flag; corrected indentation in Install Nix step.
tests/test_redeeming.py Introduced a suite of asynchronous tests for ticket redemption and aggregation functionalities, including tests for unredeemed tickets, redeeming tickets via API, and managing ticket statistics across various scenarios.

Possibly related PRs

  • Fix failing unit tests #6492: This PR addresses enhancements to asynchronous handling and error management related to ticket processing, which may connect to the modifications in ticket management functions in the main PR.
  • Add HTTPS server communication tests #6500: This PR introduces tests for HTTPS communication, which may relate to the new run_hopli_cmd function added in the main PR that executes commands, potentially including those for secure communications.
  • Fix the default min_redeem_hopr value to 0.09 wxHOPR #6523: The adjustments to the ticket redemption strategy in this PR could be relevant to the changes made in the main PR regarding ticket management functions, particularly with the focus on winning probabilities and ticket values.

Suggested labels

crate:core-strategy

Suggested reviewers

  • Teebor-Choka

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.

Updated TicketSelector to support multiple channels and added new fields like win_prob_lt. Implemented ticket rejection logic for tickets below a new minimum winning probability.
…g probability

Refactor ticket marking to use a unified `mark_tickets_as` method with the new `TicketMarker` enum. This enhancement simplifies ticket operations, replaces individual marking methods, and ensures consistent statistical updates. Updated tests and documentation to support this change.
@github-actions github-actions bot added the dependencies Pull requests that update a dependency file label Sep 26, 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 comments (1)
.github/workflows/tests.yaml (1)

Line range hint 158-214: Expanded test coverage and improved consistency. Consider version pinning.

The changes to the tests-smoke job are excellent improvements:

  1. The addition of new test suites ('redeeming', 'rest_api', and 'win_prob') enhances the coverage of the smoke tests.
  2. The Cloud SDK setup and snapshot handling changes are consistent with those in the tests-smoke-websocket job, which improves the overall structure and reliability of the workflow.

These modifications contribute to a more comprehensive and coherent testing process.

As suggested for the tests-smoke-websocket job, consider pinning the exact version of the Cloud SDK in the setup step:

- name: Set up Cloud SDK
  uses: google-github-actions/setup-gcloud@v2
  with:
    version: '363.0.0'

This change would ensure consistency across jobs and improve reproducibility.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: ASSERTIVE

📥 Commits

Files that changed from the base of the PR and between 5785d64 and ff58c44.

📒 Files selected for processing (3)
  • .github/workflows/tests.yaml (5 hunks)
  • scripts/run-local-anvil.sh (1 hunks)
  • tests/conftest.py (7 hunks)
🔇 Additional comments (4)
.github/workflows/tests.yaml (1)

103-111: Improved snapshot handling and verification.

The changes to the snapshot download and verification process are well-implemented:

  1. The use of the --recursive flag in the gcloud storage rsync command ensures all files and subdirectories are synced.
  2. The standardized destination path (smoke_test_snapshot) improves consistency.
  3. The addition of the "Check snapshot" step helps verify the download's success.

These improvements enhance the reliability and consistency of the snapshot handling process.

tests/conftest.py (3)

7-7: LGTM: Import statements updated

The addition of the re module import and the inclusion of CalledProcessError in the subprocess import are appropriate for the new run_hopli_cmd function introduced later in the file.

Also applies to: 11-11


127-127: LGTM: Node 6 configuration updated for lower winning probability

The change of Node 6's configuration file to "barebone-lower-win-prob.cfg.yaml" aligns with the PR objective of testing lowered winning probabilities. This modification ensures that Node 6 is set up correctly for the new test scenarios.


218-220: LGTM: Improved logging in snapshot_reuse function

The addition of logging for copying the anvil state file enhances the visibility of the snapshot reuse process. This will help with debugging and understanding the test setup process.

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

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: ASSERTIVE

📥 Commits

Files that changed from the base of the PR and between ff58c44 and 54e6bf6.

📒 Files selected for processing (2)
  • .github/workflows/tests.yaml (5 hunks)
  • tests/conftest.py (6 hunks)
🔇 Additional comments (7)
.github/workflows/tests.yaml (5)

84-88: Consider pinning the Cloud SDK to an exact version.

While adding the Cloud SDK setup step is a good improvement, it's recommended to pin to an exact version instead of using a minimum version constraint. This ensures consistent behavior across different environments and CI runs.

As suggested in a previous review:

- name: Set up Cloud SDK
  uses: google-github-actions/setup-gcloud@v2
  with:
    version: '363.0.0'

This change would improve reproducibility and prevent potential issues from unexpected updates.


103-108: Improved snapshot download process.

The changes to the snapshot download step are beneficial:

  1. Standardizing the snapshot storage path to smoke_test_snapshot/snapshot improves consistency and makes it easier to manage snapshots across different test suites.
  2. Adding the --recursive flag to the gcloud storage rsync command ensures that all nested directories and files are properly synchronized, which is crucial for comprehensive snapshot management.

These improvements align with best practices for cloud storage operations and should enhance the reliability of the snapshot download process.


117-123: Improved snapshot upload configuration.

The changes to the snapshot upload step are well-considered:

  1. Changing the destination path to hoprnet-test-artifacts/smoke_test_snapshot aligns with the standardization implemented in the download step. This consistency improves the overall organization and manageability of test artifacts.

  2. Setting gzip: false is appropriate for snapshot files. This ensures that the files are uploaded without additional compression, which is beneficial for snapshots that may already be compressed or contain binary data.

These modifications enhance the reliability and efficiency of the snapshot upload process.


159-162: Expanded test coverage with new test suites.

The addition of new test suites ('redeeming', 'rest_api', and 'win_prob') to the matrix strategy is a significant improvement:

  1. It expands the coverage of the smoke tests, enhancing the overall quality assurance process.
  2. The 'win_prob' suite aligns perfectly with the PR objective of adding E2E tests for lowered winning probabilities.
  3. The 'rest_api' suite suggests improved testing of API endpoints, which is crucial for ensuring the reliability of the application's interface.
  4. The 'redeeming' suite likely focuses on ticket redemption processes, which is important given the changes in winning probabilities.

These additions demonstrate a comprehensive approach to testing, covering various aspects of the system's functionality.


177-180: Consistent improvements across jobs, with a suggestion for Cloud SDK setup.

The changes to the tests-smoke job mirror those in the tests-smoke-websocket job, which is excellent for maintaining consistency across the workflow:

  1. The addition of the Cloud SDK setup step ensures that necessary tools are available for both jobs.
  2. The modifications to snapshot download and upload steps standardize the process across different test suites.

These changes improve the overall structure and reliability of the workflow. However, as mentioned earlier, consider pinning the Cloud SDK to an exact version for better reproducibility:

- name: Set up Cloud SDK
  uses: google-github-actions/setup-gcloud@v2
  with:
    version: '363.0.0'

This change would ensure consistent behavior across different environments and CI runs for both jobs.

Also applies to: 196-201, 210-216

tests/conftest.py (2)

127-127: LGTM: Removed NETWORK2 references and updated Node 6 configuration

The changes align well with the PR objectives:

  1. Node 6's configuration file has been updated to "barebone-lower-win-prob.cfg.yaml", which supports testing lowered winning probabilities.
  2. The removal of commented-out code related to NETWORK2 improves code cleanliness.

These modifications effectively streamline the testing framework for the new scenarios with lowered winning probabilities.

Also applies to: 511-512


279-291: LGTM: Updated snapshot validation process

The changes to the snapshot_usable function improve the snapshot validation process by:

  1. Including checks for new configuration files (e.g., "barebone-lower-win-prob.cfg.yaml").
  2. Ensuring that all necessary node-specific files are present in the snapshot.

These updates enhance the reliability of the snapshot system, which is crucial for efficient and consistent testing.

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

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: ASSERTIVE

📥 Commits

Files that changed from the base of the PR and between 54e6bf6 and 5407b64.

📒 Files selected for processing (1)
  • tests/conftest.py (7 hunks)
🧰 Additional context used
📓 Learnings (1)
tests/conftest.py (1)
Learnt from: NumberFour8
PR: hoprnet/hoprnet#6511
File: tests/conftest.py:147-149
Timestamp: 2024-10-01T16:57:58.727Z
Learning: When a user indicates that a comment is invalid and requests not to notify, acknowledge their request and avoid similar notifications in future.
🔇 Additional comments (2)
tests/conftest.py (2)

7-7: LGTM: New imports added

The addition of re and CalledProcessError imports suggests new functionality related to regular expressions and subprocess error handling. These changes align with the new run_hopli_cmd function introduced later in the file.

Also applies to: 11-11


127-127: LGTM: Updated Node 6 configuration for lower winning probability

The change of Node 6's configuration file to "barebone-lower-win-prob.cfg.yaml" aligns with the PR objective of testing lowered winning probabilities. This modification ensures that Node 6 is set up correctly for the new test scenarios.

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.yaml
Review profile: ASSERTIVE

📥 Commits

Files that changed from the base of the PR and between 5407b64 and 3a481af.

📒 Files selected for processing (1)
  • tests/conftest.py (9 hunks)
🧰 Additional context used
📓 Learnings (1)
tests/conftest.py (1)
Learnt from: NumberFour8
PR: hoprnet/hoprnet#6511
File: tests/conftest.py:147-149
Timestamp: 2024-10-01T16:57:58.727Z
Learning: When a user indicates that a comment is invalid and requests not to notify, acknowledge their request and avoid similar notifications in future.
🔇 Additional comments (5)
tests/conftest.py (5)

7-7: Importing re module is appropriate

The addition of import re is necessary for the regular expression operations used later in the code.


127-127: Updated configuration for Node 6 aligns with PR objectives

Changing Node 6's configuration to "barebone-lower-win-prob.cfg.yaml" is consistent with the goal of testing lowered winning probabilities.


147-149: Function renaming accurately reflects its purpose

Renaming the function to nodes_with_lower_outgoing_win_prob makes its purpose clearer, indicating that it returns nodes with a lower outgoing ticket winning probability.


283-298: Snapshot verification enhancements are valid

Including protocol-config.json and node-specific files in expected_files improves the robustness of snapshot verification. The iterative check ensures all necessary files are present.


352-354: Addition of is_node_ready function improves readiness checks

Introducing the is_node_ready function provides a more granular approach to determine when a node is fully ready, enhancing the reliability of the startup process.

Also applies to: 359-359

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

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: ASSERTIVE

📥 Commits

Files that changed from the base of the PR and between 5ad20ee and 6e3e69b.

📒 Files selected for processing (1)
  • tests/test_redeeming.py (1 hunks)
🔇 Additional comments (6)
tests/test_redeeming.py (6)

15-21: Well-structured test for unredeemed tickets without message transmission

The test test_hoprd_should_not_have_unredeemed_tickets_without_sending_messages correctly verifies that a node has no unredeemed tickets before any messages are sent. The use of parameterization ensures coverage across different nodes.


136-136: ⚠️ Potential issue

Ensure integer division when calculating message_count

Similar to line 58, ensure that integer division is used to prevent accidental float-to-integer conversion which can lead to incorrect message_count.

Apply this diff:

-message_count = int(TICKET_AGGREGATION_THRESHOLD / 10)
+message_count = TICKET_AGGREGATION_THRESHOLD // 10

Likely invalid or redundant comment.


160-160: 🛠️ Refactor suggestion

Avoid using fixed sleep durations in tests

Using await asyncio.sleep(10) can lead to longer test times and flakiness. It's better to wait for a specific condition, such as checking if aggregation has completed.

Replace the fixed sleep with a polling mechanism:

-await asyncio.sleep(10)  # wait for aggregation to finish before redeeming
+timeout = 30
+start_time = asyncio.get_event_loop().time()
+while True:
+    # Implement a condition check appropriate for your aggregation completion
+    if await is_aggregation_complete(swarm7[route[1]]):
+        break
+    elif asyncio.get_event_loop().time() - start_time > timeout:
+        raise TimeoutError("Aggregation did not complete in time")
+    await asyncio.sleep(1)

Ensure that you implement is_aggregation_complete to accurately check the aggregation status.

Likely invalid or redundant comment.


182-184: ⚠️ Potential issue

Add validation to prevent IndexError due to insufficient route length

Accessing route[1] and route[-1] assumes that route has at least two elements. If route is shorter, this will raise an IndexError.

Apply this diff to add a safeguard:

+assert len(route) >= 2, "Route must contain at least two nodes"
 await send_and_receive_packets_with_pop(
     packets, src=swarm7[route[0]], dest=swarm7[route[-1]], path=[swarm7[route[1]].peer_id]
 )

Likely invalid or redundant comment.


93-96: 🧹 Nitpick (assertive)

Correct the indentation of the multi-line assertion

The assertion spanning lines 93-96 is over-indented, which may affect readability and could potentially lead to misunderstandings of the code structure.

Apply this diff to adjust the indentation:

 assert (
-                   balance_str_to_int(statistics_after_redemption.redeemed_value)
-                   - balance_str_to_int(statistics_after.redeemed_value)
-           ) == (len(packets) * TICKET_PRICE_PER_HOP)
+    balance_str_to_int(statistics_after_redemption.redeemed_value)
+    - balance_str_to_int(statistics_after.redeemed_value)
+) == (len(packets) * TICKET_PRICE_PER_HOP)

Likely invalid or redundant comment.


23-51: 🛠️ Refactor suggestion

Consider limiting retries in channel_redeem_tickets to prevent potential infinite loops

The channel_redeem_tickets function contains a while True loop without a termination condition other than success. While this ensures eventual completion if the channel redeems successfully, it could lead to an infinite loop if the redemption continuously fails.

Apply this diff to limit the number of retries:

 async def channel_redeem_tickets(api: HoprdAPI, channel: str):
+    max_retries = 40
+    retries = 0
     while True:
         if await api.channel_redeem_tickets(channel):
             break
         else:
             await asyncio.sleep(0.5)
+            retries += 1
+            if retries >= max_retries:
+                raise Exception("Max retries reached while redeeming tickets")

Likely invalid or redundant comment.

@NumberFour8 NumberFour8 merged commit 5292e37 into master Oct 2, 2024
27 of 28 checks passed
@NumberFour8 NumberFour8 deleted the lukas/winning-prob-tests branch October 2, 2024 07:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants