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

test: Add P2P tests for Schema Update adding field #1182

Merged
merged 7 commits into from
Mar 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
226 changes: 226 additions & 0 deletions tests/integration/net/state/simple/peer/with_create_add_field_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,226 @@
// 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/immutable"

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

func TestP2PPeerCreateWithNewFieldSyncsDocsToOlderSchemaVersion(t *testing.T) {
test := testUtils.TestCase{
Actions: []any{
testUtils.RandomNetworkingConfig(),
testUtils.RandomNetworkingConfig(),
testUtils.SchemaUpdate{
Schema: `
type Users {
Name: String
}
`,
},
testUtils.SchemaPatch{
// Patch the schema on the node that we will directly create a doc on
NodeID: immutable.Some(0),
Patch: `
[
{ "op": "add", "path": "/Users/Schema/Fields/-", "value": {"Name": "Email", "Kind": 11} }
]
`,
},
testUtils.ConnectPeers{
SourceNodeID: 1,
TargetNodeID: 0,
},
testUtils.SubscribeToCollection{
NodeID: 1,
CollectionID: 0,
},
testUtils.CreateDoc{
NodeID: immutable.Some(0),
Doc: `{
"Name": "John",
"Email": "[email protected]"
}`,
},
testUtils.WaitForSync{},
testUtils.Request{
NodeID: immutable.Some(0),
Request: `query {
Users {
Name
Email
}
}`,
Results: []map[string]any{
{
"Name": "John",
"Email": "[email protected]",
},
},
},
testUtils.Request{
// John should still be synced to the second node, even though it has
// not been updated to contain the new 'Email' field.
NodeID: immutable.Some(1),
Request: `query {
Users {
Name
}
}`,
Results: []map[string]any{
{
"Name": "John",
},
},
},
},
}

testUtils.ExecuteTestCase(t, []string{"Users"}, test)
}

func TestP2PPeerCreateWithNewFieldSyncsDocsToNewerSchemaVersion(t *testing.T) {
test := testUtils.TestCase{
Actions: []any{
testUtils.RandomNetworkingConfig(),
testUtils.RandomNetworkingConfig(),
testUtils.SchemaUpdate{
Schema: `
type Users {
Name: String
}
`,
},
testUtils.SchemaPatch{
// Patch the schema on the node that we will sync docs to
NodeID: immutable.Some(1),
Patch: `
[
{ "op": "add", "path": "/Users/Schema/Fields/-", "value": {"Name": "Email", "Kind": 11} }
]
`,
},
testUtils.ConnectPeers{
SourceNodeID: 1,
TargetNodeID: 0,
},
testUtils.SubscribeToCollection{
NodeID: 1,
CollectionID: 0,
},
testUtils.CreateDoc{
NodeID: immutable.Some(0),
Doc: `{
"Name": "John"
}`,
},
testUtils.WaitForSync{},
testUtils.Request{
// John should still be synced to the second node, even though it has
// been updated with a new 'Email' field that does not exist on the
// source node.
Request: `query {
Users {
Name
}
}`,
Results: []map[string]any{
{
"Name": "John",
},
},
},
},
}

testUtils.ExecuteTestCase(t, []string{"Users"}, test)
}

// Documentation test: This is undesirable behaviour and the test should be
// updated once the behaviour has been fixed.
// Issue: https://github.com/sourcenetwork/defradb/issues/1185
func TestP2PPeerCreateWithNewFieldSyncsDocsToUpdatedSchemaVersion(t *testing.T) {
test := testUtils.TestCase{
Actions: []any{
testUtils.RandomNetworkingConfig(),
testUtils.RandomNetworkingConfig(),
testUtils.SchemaUpdate{
Schema: `
type Users {
Name: String
}
`,
},
testUtils.SchemaPatch{
// Patch the schema on all nodes
Patch: `
[
{ "op": "add", "path": "/Users/Schema/Fields/-", "value": {"Name": "Email", "Kind": 11} }
]
`,
},
testUtils.ConnectPeers{
SourceNodeID: 1,
TargetNodeID: 0,
},
testUtils.SubscribeToCollection{
NodeID: 1,
CollectionID: 0,
},
testUtils.CreateDoc{
NodeID: immutable.Some(0),
shahzadlone marked this conversation as resolved.
Show resolved Hide resolved
Doc: `{
"Name": "John",
"Email": "[email protected]"
}`,
},
testUtils.WaitForSync{},
testUtils.Request{
NodeID: immutable.Some(0),
Request: `query {
Users {
Name
Email
}
}`,
Results: []map[string]any{
{
"Name": "John",
"Email": "[email protected]",
},
},
},
testUtils.Request{
// Even though 'Email' exists on both nodes, the value of the field has not
// successfully been synced.
NodeID: immutable.Some(1),
Request: `query {
Users {
Name
Email
}
}`,
Results: []map[string]any{
{
"Name": "John",
"Email": nil,
},
},
},
},
}

testUtils.ExecuteTestCase(t, []string{"Users"}, test)
}
Loading