Skip to content

Commit

Permalink
Expand tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewSisley committed Dec 30, 2022
1 parent ae56fa4 commit 70121bb
Show file tree
Hide file tree
Showing 7 changed files with 537 additions and 0 deletions.
64 changes: 64 additions & 0 deletions tests/integration/net/state_driven/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_driven"
)

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)
}
141 changes: 141 additions & 0 deletions tests/integration/net/state_driven/peer/with_update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,96 @@ import (
testUtils "github.com/sourcenetwork/defradb/tests/integration/net/state_driven"
)

// The parent-child distinction in these tests is as much documentation and test
// of the test system as of production. See it as a santity check of sorts.
func TestP2PWithSingleDocumentSingleUpdateFromChild(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": "John",
"Age": 21
}`,
},
Updates: map[int]map[int][]string{
0: {
0: {
`{
"Age": 60
}`,
},
},
},
Results: map[int]map[int]map[string]any{
0: {
0: {
"Age": uint64(60),
},
},
1: {
0: {
"Age": uint64(60),
},
},
},
}

testUtils.ExecuteTestCase(t, test)
}

// The parent-child distinction in these tests is as much documentation and test
// of the test system as of production. See it as a santity check of sorts.
func TestP2PWithSingleDocumentSingleUpdateFromParent(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": "John",
"Age": 21
}`,
},
Updates: map[int]map[int][]string{
1: {
0: {
`{
"Age": 60
}`,
},
},
},
Results: map[int]map[int]map[string]any{
0: {
0: {
"Age": uint64(60),
},
},
1: {
0: {
"Age": uint64(60),
},
},
},
}

testUtils.ExecuteTestCase(t, test)
}

// TestP2PWithSingleDocumentUpdatePerNode tests document syncing between two nodes with a single update per node
func TestP2PWithSingleDocumentUpdatePerNode(t *testing.T) {
test := testUtils.P2PTestCase{
Expand Down Expand Up @@ -68,6 +158,57 @@ func TestP2PWithSingleDocumentUpdatePerNode(t *testing.T) {
testUtils.ExecuteTestCase(t, test)
}

func TestP2PWithSingleDocumentSingleUpdateDoesNotSyncToNonPeerNode(t *testing.T) {
test := testUtils.P2PTestCase{
NodeConfig: []*config.Config{
testUtils.RandomNetworkingConfig(),
testUtils.RandomNetworkingConfig(),
// This last node is not marked for peer sync
testUtils.RandomNetworkingConfig(),
},
NodePeers: map[int][]int{
1: {
0,
},
},
SeedDocuments: map[int]string{
0: `{
"Name": "John",
"Age": 21
}`,
},
Updates: map[int]map[int][]string{
0: {
0: {
`{
"Age": 60
}`,
},
},
},
Results: map[int]map[int]map[string]any{
0: {
0: {
"Age": uint64(60),
},
},
1: {
0: {
"Age": uint64(60),
},
},
2: {
// Update should not be synced to this node
0: {
"Age": uint64(21),
},
},
},
}

testUtils.ExecuteTestCase(t, test)
}

// TestP2PWithMultipleDocumentUpdatesPerNode tests document syncing between two nodes with multiple updates per node.
func TestP2PWithMultipleDocumentUpdatesPerNode(t *testing.T) {
test := testUtils.P2PTestCase{
Expand Down
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_replicator_test

/*
import (
"testing"
"github.com/sourcenetwork/defradb/config"
testUtils "github.com/sourcenetwork/defradb/tests/integration/net/state_driven"
)
*/

/*
// This test fails and should be uncommented once the behaviour is corrected
// The mode of failure is somewhat flaky, possibly due to the test framework
// however I do not believe the framework should accomodate this (the bug
// looks to be a production issue). Likely part of:
// https://github.com/sourcenetwork/defradb/issues/1000
func TestP2PPeerReplicatorWithCreate(t *testing.T) {
test := testUtils.P2PTestCase{
NodeConfig: []*config.Config{
testUtils.RandomNetworkingConfig(),
testUtils.RandomNetworkingConfig(),
testUtils.RandomNetworkingConfig(),
},
NodePeers: map[int][]int{
1: {
0,
},
},
NodeReplicators: map[int][]int{
0: {
2,
},
},
SeedDocuments: map[int]string{
0: `{
"Name": "John",
"Age": 21
}`,
},
Creates: map[int]map[int]string{
0: {
1: `{
"Name": "Shahzad",
"Age": 3000
}`,
},
},
Results: map[int]map[int]map[string]any{
0: {
0: {
"Age": uint64(21),
},
1: {
"Age": uint64(3000),
},
},
1: {
0: {
"Age": uint64(21),
},
},
2: {
0: {
"Age": uint64(21),
},
1: {
"Age": uint64(3000),
},
},
},
}
testUtils.ExecuteTestCase(t, test)
}
*/
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// 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_replicator_test

import (
"testing"

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

// This test documents a bug and the behaviour should be corrected
// https://github.com/sourcenetwork/defradb/issues/1000
func TestP2PPeerReplicatorWithUpdate(t *testing.T) {
test := testUtils.P2PTestCase{
NodeConfig: []*config.Config{
testUtils.RandomNetworkingConfig(),
testUtils.RandomNetworkingConfig(),
testUtils.RandomNetworkingConfig(),
},
NodePeers: map[int][]int{
1: {
0,
},
},
NodeReplicators: map[int][]int{
0: {
2,
},
},
SeedDocuments: map[int]string{
0: `{
"Name": "John",
"Age": 21
}`,
},
Updates: map[int]map[int][]string{
0: {
0: {
`{
"Age": 60
}`,
},
},
},
Results: map[int]map[int]map[string]any{
0: {
0: {
"Age": uint64(60),
},
},
1: {
0: {
"Age": uint64(60),
},
},
2: {
0: {
// This is incorrect behaviour - node 2 should not
// be updated and this value should be `21`
"Age": uint64(60),
},
},
},
}

testUtils.ExecuteTestCase(t, test)
}
Loading

0 comments on commit 70121bb

Please sign in to comment.