Skip to content

Commit

Permalink
test: Add P2P tests for relational docs (sourcenetwork#1042)
Browse files Browse the repository at this point in the history
* Remove unused property

* Allow wait group to complete on timeout

* Move existing tests to simple dir

* Pass schema in as param

No tests have changed in this commit, they have just moved and the collection index added to the relevant test case properties.

* Correctly calculate expected waits for peers

Updates for 'Creates' documents were incorrectly waited for,  resulting in false negative test results.

* Add one to many p2p tests
  • Loading branch information
AndrewSisley authored Jan 19, 2023
1 parent d0c2a4b commit 6aca3b4
Show file tree
Hide file tree
Showing 12 changed files with 627 additions and 273 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// 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

import (
"testing"

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

// This test asserts that relational documents do not fail to sync if their related
// document does not exist at the destination.
func TestP2POneToManyPeerWithCreateUpdateLinkingSyncedDocToUnsyncedDoc(t *testing.T) {
test := testUtils.P2PTestCase{
NodeConfig: []*config.Config{
testUtils.RandomNetworkingConfig(),
testUtils.RandomNetworkingConfig(),
},
NodePeers: map[int][]int{
1: {
0,
},
},
SeedDocuments: map[int]map[int]string{
1: {
0: `{
"Name": "Gulistan"
}`,
},
},
Creates: map[int]map[int]map[int]string{
0: {
0: {
// NodePeers do not sync new documents so this will not be synced
// to node 1.
1: `{
"Name": "Saadi"
}`,
},
},
},
Updates: map[int]map[int]map[int][]string{
0: {
1: {
0: {
`{
"Author_id": "bae-52b9170d-b77a-5887-b877-cbdbb99b009f"
}`,
},
},
},
},
Results: map[int]map[int]map[string]any{
0: {
1: {
"Name": "Saadi",
},
0: {
"Name": "Gulistan",
"Author_id": "bae-52b9170d-b77a-5887-b877-cbdbb99b009f",
},
},
1: {
0: {
"Name": "Gulistan",
"Author_id": "bae-52b9170d-b77a-5887-b877-cbdbb99b009f",
},
// "Saadi" was not synced to node 1, the update did not
// result in an error and synced to relational id even though "Saadi"
// does not exist in this node.
},
},
}

one_to_many.ExecuteTestCase(t, test)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// Copyright 2023 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 replicator

import (
"testing"

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

// TestP2FullPReplicator tests document syncing between a node and a replicator.
func TestP2POneToManyReplicator(t *testing.T) {
test := testUtils.P2PTestCase{
NodeConfig: []*config.Config{
testUtils.RandomNetworkingConfig(),
testUtils.RandomNetworkingConfig(),
},
NodeReplicators: map[int][]int{
0: {
1,
},
},
Creates: map[int]map[int]map[int]string{
0: {
0: {
0: `{
"Name": "Saadi"
}`,
},
1: {
1: `{
"Name": "Gulistan",
"Author_id": "bae-52b9170d-b77a-5887-b877-cbdbb99b009f"
}`,
},
},
},
Results: map[int]map[int]map[string]any{
0: {
0: {
"Name": "Saadi",
},
1: {
"Name": "Gulistan",
"Author_id": "bae-52b9170d-b77a-5887-b877-cbdbb99b009f",
},
},
1: {
0: {
"Name": "Saadi",
},
1: {
"Name": "Gulistan",
"Author_id": "bae-52b9170d-b77a-5887-b877-cbdbb99b009f",
},
},
},
}

one_to_many.ExecuteTestCase(t, test)
}
32 changes: 32 additions & 0 deletions tests/integration/net/state/one_to_many/utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright 2023 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 one_to_many

import (
"testing"

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

var schema = (`
type Author {
Name: String
Books: [Book]
}
type Book {
Name: String
Author: Author
}
`)

func ExecuteTestCase(t *testing.T, test testUtils.P2PTestCase) {
testUtils.ExecuteTestCase(t, schema, []string{"Author", "Book"}, test)
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (

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

func TestP2PCreateDoesNotSync(t *testing.T) {
Expand All @@ -28,20 +29,24 @@ func TestP2PCreateDoesNotSync(t *testing.T) {
0,
},
},
SeedDocuments: map[int]string{
0: `{
"Name": "Shahzad",
"Age": 300
}`,
},
Creates: map[int]map[int]string{
SeedDocuments: map[int]map[int]string{
0: {
1: `{
"Name": "John",
"Age": 21
0: `{
"Name": "Shahzad",
"Age": 300
}`,
},
},
Creates: map[int]map[int]map[int]string{
0: {
0: {
1: `{
"Name": "John",
"Age": 21
}`,
},
},
},
Results: map[int]map[int]map[string]any{
0: {
0: {
Expand All @@ -60,5 +65,5 @@ func TestP2PCreateDoesNotSync(t *testing.T) {
},
}

testUtils.ExecuteTestCase(t, test)
simple.ExecuteTestCase(t, test)
}
Loading

0 comments on commit 6aca3b4

Please sign in to comment.