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

Improve testgossipinternal file #1207

Open
diegomrsantos opened this issue Oct 2, 2024 · 0 comments
Open

Improve testgossipinternal file #1207

diegomrsantos opened this issue Oct 2, 2024 · 0 comments

Comments

@diegomrsantos
Copy link
Contributor

diegomrsantos commented Oct 2, 2024

Summary

A more descriptive name should be given to this file. In addition, there is noticeable repetition in the test cases, particularly around the setup and teardown of GossipSub instances and the repeated creation of Connection objects across various test cases. These redundant steps are affecting the maintainability and readability of the code.

Details

Most test cases include similar patterns:

  1. GossipSub Initialization: Each test initializes a GossipSub instance with a set of topic parameters, mesh, fanout, and gossipsub fields.
  2. Connection Setup: Every test manually creates and configures Connection objects, assigns PeerId values, and links them with PubSubPeer instances.
  3. Teardown Process: Each test includes logic for stopping the switch and closing all connections, which is similarly repeated.

This repetition can be avoided by:

  • Extracting common initialization logic for GossipSub and Connection into a helper function.
  • Extracting common teardown steps into a shared teardown function.
  • Using these helper functions across all tests to reduce the repetitive code.

Possible Fix

  • Introduce helper functions for setting up GossipSub with default topic and peer configurations. Example:
    • proc setupGossipSubWithPeers(numPeers: int): (GossipSub, seq[Connection]) could handle the creation of the GossipSub instance and its associated connections.
  • Teardown Helper: Refactor the connection teardown into proc teardownGossipSub(gossipSub: GossipSub, conns: seq[Connection]) to avoid redundant cleanup logic.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: new
Development

No branches or pull requests

1 participant