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

Draft
wants to merge 26 commits into
base: master
Choose a base branch
from

Conversation

shashankshampi
Copy link

@shashankshampi shashankshampi commented Sep 26, 2024

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

Part 2:

TC6.1: Verify that peers can correctly join a topic using JOIN(topic).
TC6.2: Ensure that peers can correctly leave a topic using LEAVE(topic).
TC6.5: Multiple peers join and leave topic simultaneously

@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 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.

Copy link
Author

Choose a reason for hiding this comment

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

done

Copy link
Collaborator

Choose a reason for hiding this comment

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

what was exactly done?

Copy link
Author

Choose a reason for hiding this comment

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

Its after subscription and I am testing subscribed value
check gossipSub.gossipsub[topic].len() == 5

@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

Copy link

@fbarbu15 fbarbu15 left a comment

Choose a reason for hiding this comment

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

LGTM

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

Choose a reason for hiding this comment

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

since the numbers of peers is set to 5 so to ensure the length is set correctly we could change to
check gossipSub.gossipsub[topic].len() == 5

Copy link
Author

Choose a reason for hiding this comment

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

done

gossipSub.topicParams[topic] = TopicParams.init()
gossipSub.gossipsub[topic] = initHashSet[PubSubPeer]()

if gossipSub.topics.len < gossipSub.topicsHigh:

Choose a reason for hiding this comment

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

since we want to test the reaction of the logic if we subscribed to more than the limit then we need to try to add more subscribtions than the limit and check the reaction

Copy link
Author

Choose a reason for hiding this comment

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

let topicCount = 15 # Total number of topics to be tested
let gossipSubParams = 10 # Subscription limit for the topics
let topicNames = toSeq(mapIt(0..topicCount - 1, "topic" & $it))

checking subscription beyond the limit and asserting it.

tests/pubsub/testgossipmembership.nim Outdated Show resolved Hide resolved
tests/pubsub/testgossipmembership.nim Outdated Show resolved Hide resolved
tests/pubsub/testgossipmembership.nim Outdated Show resolved Hide resolved
tests/pubsub/testgossipmembership.nim Outdated Show resolved Hide resolved
tests/pubsub/testgossipmembership.nim Outdated Show resolved Hide resolved
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":
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 still not checking changes to the mesh.

Copy link
Author

Choose a reason for hiding this comment

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

Mesh test is written separately in PR Part 2 as per designed Test case

  1. "handle JOIN topic and mesh is updated"
  2. "handle LEAVE topic and mesh is updated"

PR: https://github.com/vacp2p/nim-libp2p/pull/1205/files

Copy link
Collaborator

Choose a reason for hiding this comment

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

Im not sure this separation is necessary tbh.

Copy link
Author

Choose a reason for hiding this comment

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

merged Part 2 PR in this PR only

Copy link
Collaborator

@diegomrsantos diegomrsantos left a comment

Choose a reason for hiding this comment

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

There are things to be addressed

Copy link
Author

@shashankshampi shashankshampi left a comment

Choose a reason for hiding this comment

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

Thanks for review.
Have addressed all review as per requirements

tests/pubsub/testgossipmembership.nim Outdated Show resolved Hide resolved
tests/pubsub/testgossipmembership.nim Outdated Show resolved Hide resolved
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
Author

Choose a reason for hiding this comment

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

done

tests/pubsub/testgossipmembership.nim Outdated Show resolved Hide resolved
tests/pubsub/testgossipmembership.nim Outdated Show resolved Hide resolved
gossipSub.topicParams[topic] = TopicParams.init()
gossipSub.gossipsub[topic] = initHashSet[PubSubPeer]()

if gossipSub.topics.len < gossipSub.topicsHigh:
Copy link
Author

Choose a reason for hiding this comment

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

let topicCount = 15 # Total number of topics to be tested
let gossipSubParams = 10 # Subscription limit for the topics
let topicNames = toSeq(mapIt(0..topicCount - 1, "topic" & $it))

checking subscription beyond the limit and asserting it.

tests/pubsub/testgossipmembership.nim Outdated Show resolved Hide resolved
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
Author

Choose a reason for hiding this comment

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

Its after subscription and I am testing subscribed value
check gossipSub.gossipsub[topic].len() == 5

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":
Copy link
Author

Choose a reason for hiding this comment

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

Mesh test is written separately in PR Part 2 as per designed Test case

  1. "handle JOIN topic and mesh is updated"
  2. "handle LEAVE topic and mesh is updated"

PR: https://github.com/vacp2p/nim-libp2p/pull/1205/files


for topic in topicNames:
if gossipSub.topics.len < gossipSub.topicsHigh:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Now that I think about this, this doesn't make a lot of sense. The limit shouldn't be handled by the test, not manually by us. This is what the test should be asserting, actually: That regardless of the amount of subscriptions done, it shouldn't exceed the limit.

P.S.: Please, remove all the PubSub usages you added as these are GossipSub cases.

Copy link
Author

Choose a reason for hiding this comment

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

PubSub removed

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.

6 participants