Skip to content

Commit

Permalink
fix: Rework the P2P integration tests (sourcenetwork#989)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
AndrewSisley authored Jan 18, 2023
1 parent 1a0fd7c commit d0c2a4b
Show file tree
Hide file tree
Showing 11 changed files with 1,584 additions and 3 deletions.
4 changes: 4 additions & 0 deletions node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,10 @@ func (n *Node) WaitForPubSubEvent(id peer.ID) error {
}

// WaitForPushLogEvent listens to the event channel for a push log event from a given peer.
//
// It will block the calling thread until an event is yielded to an internal channel. This
// event is not nessecarily the next event and is dependent on the number of concurrent callers
// (each event will only notify a single caller, not all of them).
func (n *Node) WaitForPushLogEvent(id peer.ID) error {
for {
select {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.

package net
package order

import (
"testing"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.

package net
package order

import (
"context"
Expand Down Expand Up @@ -220,7 +220,7 @@ func executeTestCase(t *testing.T, test P2PTestCase) {
require.NoError(t, err)

if i == 0 {
dockeys = append(dockeys, d...)
dockeys = d
}
nodes = append(nodes, n)
}
Expand Down
64 changes: 64 additions & 0 deletions tests/integration/net/state/peer/with_create_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// Copyright 2022 Democratized Data Foundation
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.

package peer_test

import (
"testing"

"github.com/sourcenetwork/defradb/config"
testUtils "github.com/sourcenetwork/defradb/tests/integration/net/state"
)

func TestP2PCreateDoesNotSync(t *testing.T) {
test := testUtils.P2PTestCase{
NodeConfig: []*config.Config{
testUtils.RandomNetworkingConfig(),
testUtils.RandomNetworkingConfig(),
},
NodePeers: map[int][]int{
1: {
0,
},
},
SeedDocuments: map[int]string{
0: `{
"Name": "Shahzad",
"Age": 300
}`,
},
Creates: map[int]map[int]string{
0: {
1: `{
"Name": "John",
"Age": 21
}`,
},
},
Results: map[int]map[int]map[string]any{
0: {
0: {
"Age": uint64(300),
},
1: {
"Age": uint64(21),
},
},
1: {
0: {
"Age": uint64(300),
},
// Peer sync should not sync new documents to nodes
},
},
}

testUtils.ExecuteTestCase(t, test)
}
Loading

0 comments on commit d0c2a4b

Please sign in to comment.