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: Expand tests for Peer subscribe actions #1287

Merged
merged 11 commits into from
Apr 5, 2023

Conversation

AndrewSisley
Copy link
Contributor

@AndrewSisley AndrewSisley commented Apr 4, 2023

Relevant issue(s)

Resolves #1281

Description

Expands the tests for Peer subscribe actions, adding basic coverage to the previously uncovered Remove and GetAll functions (available through the CLI), and basic error testing for Add and Remove.

One extremely minor production issue found and corrected (commit Return empty array instead of default). Not sure such an inconsistency would be visible to users, as the only exposure would be via CLI or http.

The function under test takes a set of schemaIDs, so the tests should be able to set multiple in the same test action - this will allow testing of the function with multiple ids.
Adds tests for subscribing to multiple collections in the same call. This is done in a new sub-directory as we will expand the number of subscription-specific tests shortly and they should not polute or by drowned out by the normal/existing p2p-peer tests.
@AndrewSisley AndrewSisley added area/testing Related to any test or testing suite area/p2p Related to the p2p networking system action/no-benchmark Skips the action that runs the benchmark. labels Apr 4, 2023
@AndrewSisley AndrewSisley added this to the DefraDB v0.5 milestone Apr 4, 2023
@AndrewSisley AndrewSisley requested a review from a team April 4, 2023 20:04
@AndrewSisley AndrewSisley self-assigned this Apr 4, 2023
@AndrewSisley AndrewSisley changed the title test: Expand tests for Peer subscribe actions test: Expand tests for Peer subscribe actions Apr 4, 2023
@AndrewSisley AndrewSisley force-pushed the sisley/test/I1281-test-p2p-rm-col branch from 13b3963 to 7867a95 Compare April 4, 2023 20:40
Whilst there is not much difference in terms of behaviour, they are still different and it notable enough to result in a test failure
@AndrewSisley AndrewSisley force-pushed the sisley/test/I1281-test-p2p-rm-col branch 2 times, most recently from 5a4f653 to 870184b Compare April 4, 2023 20:41
@AndrewSisley AndrewSisley force-pushed the sisley/test/I1281-test-p2p-rm-col branch from 870184b to 31bc6c7 Compare April 4, 2023 20:41
@codecov
Copy link

codecov bot commented Apr 4, 2023

Codecov Report

Merging #1287 (f054282) into develop (371a43f) will increase coverage by 0.29%.
The diff coverage is 54.54%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #1287      +/-   ##
===========================================
+ Coverage    70.26%   70.56%   +0.29%     
===========================================
  Files          184      184              
  Lines        17798    17817      +19     
===========================================
+ Hits         12506    12572      +66     
+ Misses        4343     4296      -47     
  Partials       949      949              
Impacted Files Coverage Δ
net/peer.go 50.97% <54.54%> (+4.80%) ⬆️

... and 9 files with indirect coverage changes

Copy link
Member

@shahzadlone shahzadlone left a comment

Choose a reason for hiding this comment

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

Looks nice on first pass, will go through all the tests in a bit more depth after my sleep.

net/peer.go Outdated
@@ -803,7 +806,10 @@ func (p *Peer) AddP2PCollections(collections []string) error {
return txn.Commit(p.ctx)
}

// RemoveP2PCollectionTopics adds the collectionID from the pubsup topics
// RemoveP2PCollectionTopics removes the given collectionIDs from the pubsup topics.
Copy link
Member

Choose a reason for hiding this comment

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

todo:

Suggested change
// RemoveP2PCollectionTopics removes the given collectionIDs from the pubsup topics.
// RemoveP2PCollections removes the given collectionIDs from the pubsup topics.

Copy link
Contributor Author

@AndrewSisley AndrewSisley Apr 5, 2023

Choose a reason for hiding this comment

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

Will sort out

  • Upadate Doc func name

net/peer.go Outdated
@@ -758,7 +758,10 @@ type EvtPubSub struct {
Peer peer.ID
}

// AddP2PCollectionTopic adds the collectionID to the pubsup topics
// AddP2PCollectionTopic adds the given collectionIDs to the pubsup topics.
Copy link
Member

Choose a reason for hiding this comment

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

todo:

Suggested change
// AddP2PCollectionTopic adds the given collectionIDs to the pubsup topics.
// AddP2PCollections adds the given collectionIDs to the pubsup topics.

Copy link
Contributor Author

@AndrewSisley AndrewSisley Apr 5, 2023

Choose a reason for hiding this comment

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

Will sort out

  • Upadate Doc func name

// The `n.Peer.RemoveP2PCollections(colIDs)` call above is calling some asynchronous functions
// for the pubsub subscription and those functions can take a bit of time to complete,
// we need to make sure this has finished before progressing.
time.Sleep(100 * time.Millisecond)
Copy link
Member

Choose a reason for hiding this comment

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

question: how did you determine that it should be 100 milliseconds?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is arbitrary, the same sleep is used for after AddP2PSubscription

Copy link
Collaborator

@fredcarle fredcarle left a comment

Choose a reason for hiding this comment

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

LGTM. There could be an extra test as suggested bellow but otherwise all good.

Copy link
Collaborator

Choose a reason for hiding this comment

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

suggestion: We could probably add a test where we specify no collection in the subscription request and it will add automatically add all collections

Copy link
Contributor Author

@AndrewSisley AndrewSisley Apr 5, 2023

Choose a reason for hiding this comment

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

The code does not look like it does that - it would just add nothing? Is a good spot either way though, as it is not tested :)

  • Close test gap

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sorry my mistake. I mixed up with replicators.

@AndrewSisley AndrewSisley merged commit c546ca4 into develop Apr 5, 2023
@AndrewSisley AndrewSisley deleted the sisley/test/I1281-test-p2p-rm-col branch April 5, 2023 18:45
shahzadlone pushed a commit that referenced this pull request Apr 13, 2023
* Expand peer P2PCollection func documentation

* Allow framework to test multi col ids for subscribe

The function under test takes a set of schemaIDs, so the tests should be able to set multiple in the same test action - this will allow testing of the function with multiple ids.

* Add tests for multiple peer subscribe

Adds tests for subscribing to multiple collections in the same call. This is done in a new sub-directory as we will expand the number of subscription-specific tests shortly and they should not polute or by drowned out by the normal/existing p2p-peer tests.

* Add tests for remove peer subscription

* Return empty array instead of default

Whilst there is not much difference in terms of behaviour, they are still different and it notable enough to result in a test failure

* Add tests for GetAllP2PCollections

* Add tests for add subscription with error

* Add error tests for remove subscription
shahzadlone pushed a commit to shahzadlone/defradb that referenced this pull request Feb 23, 2024
* Expand peer P2PCollection func documentation

* Allow framework to test multi col ids for subscribe

The function under test takes a set of schemaIDs, so the tests should be able to set multiple in the same test action - this will allow testing of the function with multiple ids.

* Add tests for multiple peer subscribe

Adds tests for subscribing to multiple collections in the same call. This is done in a new sub-directory as we will expand the number of subscription-specific tests shortly and they should not polute or by drowned out by the normal/existing p2p-peer tests.

* Add tests for remove peer subscription

* Return empty array instead of default

Whilst there is not much difference in terms of behaviour, they are still different and it notable enough to result in a test failure

* Add tests for GetAllP2PCollections

* Add tests for add subscription with error

* Add error tests for remove subscription
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
action/no-benchmark Skips the action that runs the benchmark. area/p2p Related to the p2p networking system area/testing Related to any test or testing suite
Projects
None yet
Development

Successfully merging this pull request may close these issues.

No automated tests for peer Remove/GetAllP2PCollections
3 participants