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

fix: Rework the P2P integration tests #989

Merged
merged 25 commits into from
Jan 18, 2023

Conversation

AndrewSisley
Copy link
Contributor

@AndrewSisley AndrewSisley commented Dec 21, 2022

Relevant issue(s)

Resolves #985

Description

I started changing stuff as the Replicator tests permitted tests to pass when they shouldn't (first commit). This PR then goes on to expand the replicator tests. Then, as my understanding grew I reworked the rest for the reasons laid out in the message body of the 3rd commit.

I am planning to expand the replicator and peer tests further (create for peer, update for replicator, and tests that configure both). I am quite new to this part of the codebase though, so it is very possible that some of that will not be possible due to me misunderstanding the desired behaviour (will probs badger Fred here). This expansion may take place in this PR if no one gets back to me before I resume work tomorrow - do let me know your thoughts in the meantime though :) New tests have been included

No production bugs have been found yet. Probable production bug found: #1000
Another prod bug found: #1031 - Waiting on this to be merged before finalizing the test code.

@AndrewSisley AndrewSisley added bug Something isn't working 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 Dec 21, 2022
@AndrewSisley AndrewSisley added this to the DefraDB v0.4 milestone Dec 21, 2022
@AndrewSisley AndrewSisley requested a review from a team December 21, 2022 01:01
@AndrewSisley AndrewSisley self-assigned this Dec 21, 2022
@AndrewSisley AndrewSisley force-pushed the sisley/fix/I985-replicator-false-positives branch from b9727e5 to 4800cd3 Compare December 21, 2022 01:05
@codecov
Copy link

codecov bot commented Dec 21, 2022

Codecov Report

Merging #989 (8b1f0d4) into develop (db76f2d) will increase coverage by 0.28%.
The diff coverage is n/a.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop     #989      +/-   ##
===========================================
+ Coverage    57.74%   58.02%   +0.28%     
===========================================
  Files          174      174              
  Lines        19563    19563              
===========================================
+ Hits         11297    11352      +55     
+ Misses        7265     7215      -50     
+ Partials      1001      996       -5     
Impacted Files Coverage Δ
node/node.go 66.38% <ø> (ø)
net/pb/net.pb.go 15.82% <0.00%> (+0.16%) ⬆️
datastore/badger/v3/datastore.go 39.12% <0.00%> (+0.32%) ⬆️
net/server.go 57.08% <0.00%> (+1.14%) ⬆️
net/process.go 77.61% <0.00%> (+2.98%) ⬆️
datastore/blockstore.go 54.94% <0.00%> (+3.29%) ⬆️
net/peer.go 50.47% <0.00%> (+6.45%) ⬆️
core/crdt/lwwreg.go 75.86% <0.00%> (+6.89%) ⬆️
net/client.go 85.36% <0.00%> (+7.31%) ⬆️
net/dialer.go 56.25% <0.00%> (+12.50%) ⬆️

@fredcarle
Copy link
Collaborator

I'm happy to see that you dived into the P2P related code. I wasn't expecting this much change on the test utility though haha. There are a few things you changed that I think shouldn't have been changed. The peer test was done in that way because it allowed for testing the pubsub process in a deterministic fashion. For each updates, the test would wait for the receiving peer to acknowledge reception and then the result would be asserted. Eventual consistency is the outcome of processing a log but not the intent of the test.

The pubsub network can only update documents that where at first created exactly the same on both nodes. Hence why the check is on a specific document and a getAllDocuments type function isn't applicable (although it could be used for the replicator tests). Create wont be possible for pubsub related tests. Update is definitely possible for the replicators though.

The key points to keep in mind is that pubsub configuration happens during the node setup while replicators are added to an already running node. Peers on the pubsub network subscribe to a specific document's updates while replicators subscribe to all actions on a collection (or any number of collections).

If you want me to get on a call to discuss this with you tomorrow feel free to reach out.

@AndrewSisley
Copy link
Contributor Author

AndrewSisley commented Dec 21, 2022

Eventual consistency is the outcome of processing a log but not the intent of the test.

No, but it is ultimately what we care about, and far more intuitive to read IMO (as well as being more consistent with all our other tests).

Create wont be possible for pubsub related tests

Correction - created records should not be synced - this is untested and needs to be tested, and previously could not be tested. We also need to test that newly created records should also not break the peer system.

The key points to keep in mind is that pubsub configuration happens during the node setup while replicators are added to an already running node. Peers on the pubsub network subscribe to a specific document's updates while replicators subscribe to all actions on a collection (or any number of collections).

I understand this, and there are large test holes described in the description that are now possible to fill. It sounds like it would be prudent to hold off on further review until I add those tests as they will do a better job at describing these holes, as well as the duplication/conflicts present in the old system.

@fredcarle
Copy link
Collaborator

No, but it is ultimately what we care about, and far more intuitive to read IMO (as well as being more consistent with all our other tests).

The way you changed the test makes it impossible to test that the peer got the update as the test will pass even if the value stays the same.

@AndrewSisley
Copy link
Contributor Author

No, but it is ultimately what we care about, and far more intuitive to read IMO (as well as being more consistent with all our other tests).

The way you changed the test makes it impossible to test that the peer got the update as the test will pass even if the value stays the same.

I dont follow. You are talking about on update? The tests show that the values have been synced, and are the same across both systems (something the prior version was unable to assert). It does not check the commit history, but that is easy enough to add if we want, and I would suggest that is highly secondary to the fact that they both have the same head value (especially given that the history is somewhat required to achieve that state, or the test would be flacky as it would only pass ~half of the time).

@fredcarle
Copy link
Collaborator

fredcarle commented Dec 21, 2022

I dont follow. You are talking about on update? The tests show that the values have been synced, and are the same across both systems (something the prior version was unable to assert).

You are asserting with anyOf which will pass regardless of either value. The previous version was able to assert that the update was received and that the value was as expected for the given update. They are both different types of test and don't provide the same guarantees. We can keep what you added but I think the original one should be kept as well. That test was very useful during development.

@AndrewSisley
Copy link
Contributor Author

I dont follow. You are talking about on update? The tests show that the values have been synced, and are the same across both systems (something the prior version was unable to assert).

You are asserting with anyOf which will pass regardless of either value. The previous version was able to assert that the update was received and that the value was as expected for the given update. They are both different types of test and don't provide the same guarantees. We can keep what you added but I think the original one should be kept as well. That test was very useful during development.

This is incorrect. AnyOf asserts that they have any of the given values, but that the values are the same across all nodes. This is stated in the docs. It is a very important distinction, and very useful public documentation IMO. The previous tests did not describe this behaviour at all, and it is very important that it is.

@AndrewSisley
Copy link
Contributor Author

AndrewSisley commented Dec 29, 2022

Actions discussed outside of github:

  • Preserve original tests - I will likely move the new code to a different directory and revert the original. I still disagree that the old are useful alongside the new, and I disagree that the old are integration tests (as they dont test publicly useful behaviour). But we did agree to do this before Christmas.

@AndrewSisley AndrewSisley force-pushed the sisley/fix/I985-replicator-false-positives branch 12 times, most recently from 0451f2e to 70121bb Compare December 30, 2022 00:06
@AndrewSisley AndrewSisley modified the milestones: DefraDB v0.4, DefraDB v0.5 Dec 30, 2022
There was a typo, and the name suggests it tests everything replicator related - and that no further tests are required
This commit merges the properties associated with the peer-tests with the properties associated with the replicator tests.  There was a lot of duplication, and it prevented testing of both peer and replicator tests within the same test case due to id/index clashes.  It also reworks the code so that the two elements work in largely the same way. It should allow replicators to test updates, and peers to test creates.

The both peer and replicator tests now assert on the final state of all databases for all nodes. This feels both more meaningful and clearer IMO, although it does add a few lines to each test, as well as some fanciness required to deal with the non-deterministic results of the peer sync tests.
Looks both overly defensive, and enables a silent failure
Is about to get crowded :)
Good spot by Fred, due to the containing if this is only ever done once anyway making the spread pointless
Not requested, but it is inconsistent with create and just generally ambiguous
Not requested, but it is inconsistent with create and just generally ambiguous
Previous behaviour was a bug that has now been fixed
Production bug has been fixed
Behaviour was correct, linked ticket has been closed
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.

This is great. Thank for engaging with the suggestions :)

@AndrewSisley
Copy link
Contributor Author

This is great. Thank for engaging with the suggestions :)

Thank you for suggesting them (and all the other related work around this) :)

@AndrewSisley AndrewSisley dismissed jsimnz’s stale review January 18, 2023 19:09

Issues addressed and corrected

@AndrewSisley AndrewSisley merged commit 019df39 into develop Jan 18, 2023
@AndrewSisley AndrewSisley deleted the sisley/fix/I985-replicator-false-positives branch January 18, 2023 19:24
shahzadlone pushed a commit that referenced this pull request Apr 13, 2023
* Duplicate net tests

In order to preserve the order driven tests

* Rework replicator tests so that each expected result is asserted upon

Deletion of pretty much any property/item in the test case will now cause it to fail, before many of these deletions would permit it to pass without asserting the expected results.

Much of this commit has been moved and reworked later, however I chose to preserve it as it highlights the behavioural change specific to this commit.

* Expand replicator tests

There was a typo, and the name suggests it tests everything replicator related - and that no further tests are required

* Refactor test library

This commit merges the properties associated with the peer-tests with the properties associated with the replicator tests.  There was a lot of duplication, and it prevented testing of both peer and replicator tests within the same test case due to id/index clashes.  It also reworks the code so that the two elements work in largely the same way. It should allow replicators to test updates, and peers to test creates.

The both peer and replicator tests now assert on the final state of all databases for all nodes. This feels both more meaningful and clearer IMO, although it does add a few lines to each test, as well as some fanciness required to deal with the non-deterministic results of the peer sync tests.

* Remove uneeded check

Looks both overly defensive, and enables a silent failure

* Breakup P2P test file

Is about to get crowded :)

* Expand tests
shahzadlone pushed a commit to shahzadlone/defradb that referenced this pull request Feb 23, 2024
* Duplicate net tests

In order to preserve the order driven tests

* Rework replicator tests so that each expected result is asserted upon

Deletion of pretty much any property/item in the test case will now cause it to fail, before many of these deletions would permit it to pass without asserting the expected results.

Much of this commit has been moved and reworked later, however I chose to preserve it as it highlights the behavioural change specific to this commit.

* Expand replicator tests

There was a typo, and the name suggests it tests everything replicator related - and that no further tests are required

* Refactor test library

This commit merges the properties associated with the peer-tests with the properties associated with the replicator tests.  There was a lot of duplication, and it prevented testing of both peer and replicator tests within the same test case due to id/index clashes.  It also reworks the code so that the two elements work in largely the same way. It should allow replicators to test updates, and peers to test creates.

The both peer and replicator tests now assert on the final state of all databases for all nodes. This feels both more meaningful and clearer IMO, although it does add a few lines to each test, as well as some fanciness required to deal with the non-deterministic results of the peer sync tests.

* Remove uneeded check

Looks both overly defensive, and enables a silent failure

* Breakup P2P test file

Is about to get crowded :)

* Expand tests
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 bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Net/utils does not assert that all ReplicatorResults are present
4 participants