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 2 Test cases covering JOIN and LEAVE Events #1205

Merged
merged 17 commits into from
Oct 16, 2024

Conversation

shashankshampi
Copy link

@shashankshampi shashankshampi commented Oct 1, 2024

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

Test Scenario: Block 6
Topic Membership Tests:

Part 2:

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

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.

Please fix the PR name, I saw on another PR that the title should be prefixed with test(gossipsub):

See #1204

tests/pubsub/testgossipmembership.nim Outdated Show resolved Hide resolved
@shashankshampi
Copy link
Author

Please fix the PR name, I saw on another PR that the title should be prefixed with test(gossipsub):

See #1204

Done

@shashankshampi shashankshampi changed the title Part 2: Test cases covering JOIN and LEAVE Events test(gossipsub): Part 2 Test cases covering JOIN and LEAVE Events Oct 1, 2024
Copy link
Collaborator

@AlejandroCabeza AlejandroCabeza left a comment

Choose a reason for hiding this comment

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

There's one issue in some of the tests, regarding SUBSCRIBING and UNSUBSCRIBING, that I feel would benefit from some clarification, as it's more complex than it may seem at first.

There's a few key things to understand those operations. For that, let's define node as the local instance and peer as a remote instance:

When node subscribes to a topic it begins listening to the messages that arrive for that topic. In order to do this, node will add that topic to node.topics. That's a PubSub feature.

When a peer connects to node, node will keeps track of peer's subscribed topics in the GossipSub.gossipsub table. If no topics are shared, it will remain as a metadata connection.

When both peer and node are connected and subscribed to the same topic, there will be an attempt to GRAFT (PRUNE being the opposite operation) them, which means converting the connecting to full-message. Esentially, both GossipSub instances will add an entry for the connected peer into mesh. When GossipSub receives a message it will send it to all peers in that topic's mesh, if any.

With all this context:

  • I didn't realise this until now (so my bad 😅) but it'd be great to have tests for both situations:

    • Node without connections
    • Node connected with some peer/s
  • Some tests are making improper use of conns.

    • In some tests it's declared but not used, or even initialised.
    • It does make sense to have it and use it (when testing the "connected" cases), but in some of those cases you're not actually initialising the variable, or triggering the connection as you may have expected.

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

Review comments resolved

@shashankshampi shashankshampi marked this pull request as ready for review October 7, 2024 03:50
@fbarbu15 fbarbu15 self-requested a review October 7, 2024 09:09
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

tests/pubsub/testgossipmembership.nim Outdated Show resolved Hide resolved

check gossipSub.mesh[topic].len == 6

# Simulate 3 peers leaving the topic by unsubscribing them individually
Copy link
Collaborator

Choose a reason for hiding this comment

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

Instead of running the excl method I'd suggest unsubscribing using the higher level unsubscribe, so we use the opposite (and public) methods.

Copy link
Author

Choose a reason for hiding this comment

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

used unsubscribe now.
Thanks done.

var peersToUnsubscribe = gossipSub.mesh[topic].toSeq()[0 .. 2]
for peer in peersToUnsubscribe:
echo "Unsubscribing peer: ", peer.peerId
gossipSub.PubSub.unsubscribe(topic, dummyHandler)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same here.

Copy link
Author

Choose a reason for hiding this comment

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

Removed PubSub

Copy link
Collaborator

@AlejandroCabeza AlejandroCabeza left a comment

Choose a reason for hiding this comment

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

A couple of importante notes:

I would recommend not using the subscribe system you're using here. The reason being it's misleading, makes you think stuff works differently than it actually does. That behaves more like a mock of sorts, than the actual expected behaviour.
I may have said that too late because I didn't wanna bother you too much, but I've realised it's quite misleading. I suggest you follow the approach I use in my tests. You can check them out here: https://github.com/vacp2p/nim-libp2p/pull/1184/files, for example in messages are not sent back to source or forwarding peer. You might need to check several test cases, as some of them are slightly more complex than others. Checking some of them might be key to get the idea.

I believe you are making some assumptions in how information flows which are not correct.
E.g.: You are calling unsubscribe multiple times on the same node on the same topic on the same unsubscribed-handler, which means nothing's going to be unsubscribed.
I suggest checking the provided docs and/or code and/or requesting a deeper explanation if that's not clear.

Following from 2. Be careful not to conform tests to the results, but the other way around. If results are not as expected you should double check your test does what it intends. If it does, then that's a signal there might be something wrong in the codebase. But absolutely never adapt the assertions just because.

EDIT: Please, apply this suggestions (if and whenever they fit) into the other PR as well). Thanks! :)

@shashankshampi shashankshampi merged commit cc8e976 into block6Test Oct 16, 2024
13 of 14 checks passed
@shashankshampi shashankshampi deleted the block6Test2 branch October 16, 2024 09:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: done
Development

Successfully merging this pull request may close these issues.

4 participants