forked from sourcenetwork/defradb
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Add P2P tests for relational docs (sourcenetwork#1042)
* 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
1 parent
d0c2a4b
commit 6aca3b4
Showing
12 changed files
with
627 additions
and
273 deletions.
There are no files selected for viewing
86 changes: 86 additions & 0 deletions
86
tests/integration/net/state/one_to_many/peer/with_create_update_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
71 changes: 71 additions & 0 deletions
71
tests/integration/net/state/one_to_many/replicator/with_create_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.