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(gossipsub): Part 1 Test cases covering subscribe and unsubscribe Events #1201

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

shashankshampi
Copy link

Test Plan: https://www.notion.so/Gossipsub-651e02d4d7894bb2ac1e4edb55f3192d

Topic Membership Tests:

Test added: (TC6.6: Verify the handling of subscription changes when the underlying pubsub framework sends SUBSCRIBE and UNSUBSCRIBE events.)

  1. Simulate the SUBSCRIBE event and check proper handling in the mesh and gossipsub structures
  2. This test will simulate an UNSUBSCRIBE event and check if the topic is removed from the relevant data structures but remains in gossipsub
  3. This test ensures that multiple topics can be subscribed to and unsubscribed from, with proper initialization of the topic structures.
  4. This test ensures that the number of subscriptions does not exceed the limit set in the GossipSub parameters

@diegomrsantos
Copy link
Collaborator

how about testgossiptopicmembership.nim?

# Addition of Designed Test cases for 6. Topic Membership Tests: https://www.notion.so/Gossipsub-651e02d4d7894bb2ac1e4edb55f3192d

# Simulate the `SUBSCRIBE` event and check proper handling in the mesh and gossipsub structures
asyncTest "handle SUBSCRIBE event":
Copy link
Collaborator

Choose a reason for hiding this comment

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

This test is very similar to

asyncTest "subscribe/unsubscribeAll":

Copy link
Author

Choose a reason for hiding this comment

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

Agree on this but little difference is there

Subscription Handler:

Newly added test (handle SUBSCRIBE event):
Uses an anonymous function when subscribing to the topic, and it does not test for the dynamic dispatch mechanism used to handle topic messages.

Existing test (subscribe/unsubscribeAll):
It defines a handler function for handling messages sent to the subscribed topic. This makes the test more practical for simulating message reception and processing. It also uses dynamic dispatch for testing the subscription and unsubscription.

You can keep the newly added test if you want a lightweight, focused check for basic subscription functionality. If not required then will remove it as it was added keeping in mind for light sanity @AlejandroCabeza

Copy link
Collaborator

Choose a reason for hiding this comment

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

Uses an anonymous function when subscribing to the topic, and it does not test for the dynamic dispatch mechanism used to handle topic messages.

This doesn't need to be tested in this test.

Copy link
Collaborator

@diegomrsantos diegomrsantos Oct 2, 2024

Choose a reason for hiding this comment

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

But we could replace the existing test with the first two you created. There's a lot of code repetition in testgossipinternal as pointed out here #1207.

Copy link
Author

Choose a reason for hiding this comment

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

Agree on it. I Will follow this as another task and can move all common lines of code to func to ensure testgossipinternal is clean with no redundant line of code in relevant file as well

Copy link
Collaborator

@diegomrsantos diegomrsantos Oct 3, 2024

Choose a reason for hiding this comment

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

Please remove asyncTest "subscribe/unsubscribeAll" in testgossipinternal.

Copy link
Author

Choose a reason for hiding this comment

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

Please remove asyncTest "subscribe/unsubscribeAll" in testgossipinternal.

Removed

@diegomrsantos
Copy link
Collaborator

We follow conventional commits for the PR title. In this case, it will start with test(gossipsub):

@shashankshampi
Copy link
Author

how about testgossiptopicmembership.nim?

I am adding other tests in the same file related to Topic Membership Tests for Join topic, leave topic, and mesh updated on peer subscribing and leaving topic.

Earlier suggestion looks fine but else will modify as per your suggestion

@shashankshampi
Copy link
Author

We follow conventional commits for the PR title. In this case, it will start with test(gossipsub):

Thanks. Will follow same in upcoming PRs

added test wrt subscribe and unsubscribe

added tests/pubsub/testgossipinternal2 file

linters

feat: rendezvous refactor (#1183)

Hello!

This PR aim to refactor rendezvous code so that it is easier to impl.
Waku rdv strategy. The hardcoded min and max TTL were out of range with
what we needed and specifying which peers to interact with is also
needed since Waku deals with peers on multiple separate shards.

I tried to keep the changes to a minimum, specifically I did not change
the name of any public procs which result in less than descriptive names
in some cases. I also wanted to return results instead of raising
exceptions but didn't. Would it be acceptable to do so?

Please advise on best practices, thank you.

---------

Co-authored-by: Ludovic Chenut <ludovic@status.im>

refactor and suite name refactor

chore(ci): Enable S3 caching for interop (#1193)

- Adds our S3 bucket for caching docker images as Protocol Labs shut
down their shared one.
- Remove the free disk space workaround that prevented the jobs from
failing for using too much space for the images.

---------

Co-authored-by: diegomrsantos <diego@status.im>

PR review comment changes
@shashankshampi shashankshampi changed the title Part 1: Test cases covering subscribe and unsubscribe Events test(gossipsub): Part 1 Test cases covering subscribe and unsubscribe Events Oct 1, 2024
@diegomrsantos
Copy link
Collaborator

how about testgossiptopicmembership.nim?

I am adding other tests in the same file related to Topic Membership Tests for Join topic, leave topic, and mesh updated on peer subscribing and leaving topic.

Earlier suggestion looks fine but else will modify as per your suggestion

I'm not sure if gossip membership makes sense.


check gossipSub.topics.contains(topic) # Check if the topic is in topics
check gossipSub.gossipsub[topic].len() > 0 # Check if topic added to gossipsub

Copy link
Collaborator

Choose a reason for hiding this comment

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

The existing text also checks gossipSub.mesh[topic].len() > 0. Is there a place defining what the tests should ensure?

Copy link
Author

Choose a reason for hiding this comment

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

Test case are designed here: 6. Topic Membership Tests (❌ To Do)
https://www.notion.so/Gossipsub-651e02d4d7894bb2ac1e4edb55f3192d

These are split tests which check individual logic rather than subscribe and unsubscribe together

Copy link
Author

Choose a reason for hiding this comment

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

Only test title is there and based on that we are adding checks to ensure that functionality. We can have details check test if required

Comment on lines 95 to 98
# Iterate over the peers and check connection handling
for peer in gossipSub.peers.values:
check peer.sendConn != nil
check not peer.sendConn.closed()
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think this is necessary.

Copy link
Author

Choose a reason for hiding this comment

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

removed. Done

let (gossipSub, conns) = setupGossipSub(topic, 5)

# Subscribe to the topic
subscribeToTopics(gossipSub, @[topic].toSeq()) # Pass topic as seq[string]
Copy link
Collaborator

Choose a reason for hiding this comment

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

.toSeq() isn't necessary

Copy link
Author

Choose a reason for hiding this comment

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

Thanks done

Comment on lines 122 to 123
check topic notin gossipSub.topics # The topic should not be in topics
check topic notin gossipSub.mesh # The topic should be removed from the mesh
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think those comments aren't necessary as the code is clear.

Copy link
Author

Choose a reason for hiding this comment

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

removed all unwanted comments
Done

let (gossipSub, conns) = setupGossipSub(topic, 5)

# Subscribe to the topic first
subscribeToTopics(gossipSub, @[topic]) # Pass topic as seq[string]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Comment here also isn't necessary.

Copy link
Author

Choose a reason for hiding this comment

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

removed
done

subscribeToTopics(gossipSub, @[topic]) # Pass topic as seq[string]

# Now unsubscribe from the topic
unsubscribeFromTopics(gossipSub, @[topic]) # Pass topic as seq[string]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Comment here also isn't necessary.

Copy link
Author

Choose a reason for hiding this comment

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

removed
Done

gossipSub.PubSub.unsubscribeAll(topic)

# Simulate the `SUBSCRIBE` to the topic and check proper handling in the mesh and gossipsub structures
asyncTest "handle SUBSCRIBE to the topic and verify connection handling":
Copy link
Collaborator

Choose a reason for hiding this comment

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

"handle SUBSCRIBE to the topic" is enough for the name.

Copy link
Author

Choose a reason for hiding this comment

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

done

check gossipSub.topics.contains(topic)

# Check if the topic is added to gossipsub and the peers list is not empty
check gossipSub.gossipsub[topic].len() > 0
Copy link
Collaborator

Choose a reason for hiding this comment

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

If we move this line before subscribeToTopics(gossipSub, @[topic]) it's already true, so we aren't testing anything here.

@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 84.55%. Comparing base (09fe199) to head (46b7125).
Report is 2 commits behind head on master.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1201      +/-   ##
==========================================
+ Coverage   84.54%   84.55%   +0.01%     
==========================================
  Files          93       93              
  Lines       16650    16681      +31     
==========================================
+ Hits        14076    14104      +28     
- Misses       2574     2577       +3     

see 6 files with indirect coverage changes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

3 participants