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 tests to assert schema id order independence #1456

Merged
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
130 changes: 130 additions & 0 deletions tests/integration/net/state/simple/replicator/with_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,3 +383,133 @@ func TestP2POneToManyReplicatorManyDocs(t *testing.T) {

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

func TestP2POneToOneReplicatorOrderIndependent(t *testing.T) {
test := testUtils.TestCase{
Actions: []any{
testUtils.RandomNetworkingConfig(),
testUtils.RandomNetworkingConfig(),
testUtils.SchemaUpdate{
NodeID: immutable.Some(0),
Schema: `
type Users {
name: String
age: Int
}
`,
},
testUtils.SchemaUpdate{
// Add the same schema to the second node but with the age and name fields in
// a different order.
NodeID: immutable.Some(1),
Schema: `
type Users {
age: Int
name: String
}
`,
},
testUtils.ConfigureReplicator{
SourceNodeID: 0,
TargetNodeID: 1,
},
testUtils.CreateDoc{
// Create John on the first (source) node only, and allow the value to sync
NodeID: immutable.Some(0),
Doc: `{
"name": "John",
"age": 21
}`,
},
testUtils.WaitForSync{},
testUtils.Request{
// The document should have been synced, and should contain the same values
// including dockey and schema version id.
Request: `query {
Users {
_key
age
name
_version {
schemaVersionId
}
}
}`,
Results: []map[string]any{
{
"_key": "bae-f54b9689-e06e-5e3a-89b3-f3aee8e64ca7",
"age": uint64(21),
"name": "John",
"_version": []map[string]any{
{
"schemaVersionId": "bafkreidovoxkxttybaew2qraoelormm63ilutzms7wlwmcr3xru44hfnta",
},
},
},
},
},
},
}

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

func TestP2POneToOneReplicatorOrderIndependentDirectCreate(t *testing.T) {
test := testUtils.TestCase{
Actions: []any{
testUtils.RandomNetworkingConfig(),
testUtils.RandomNetworkingConfig(),
testUtils.SchemaUpdate{
NodeID: immutable.Some(0),
Schema: `
type Users {
name: String
age: Int
}
`,
},
testUtils.SchemaUpdate{
// Add the same schema to the second node but with the age and name fields in
// a different order.
NodeID: immutable.Some(1),
Schema: `
type Users {
age: Int
name: String
}
`,
},
testUtils.CreateDoc{
// Create the document directly and indepentently on each node.
Doc: `{
"name": "John",
"age": 21
}`,
},
testUtils.Request{
// Assert that the dockey and schema version id are the same across all nodes,
// even though the schema field order is different.
Request: `query {
Users {
_key
_version {
schemaVersionId
}
}
}`,
Results: []map[string]any{
{
"_key": "bae-f54b9689-e06e-5e3a-89b3-f3aee8e64ca7",
"_version": []map[string]any{
{
"schemaVersionId": "bafkreidovoxkxttybaew2qraoelormm63ilutzms7wlwmcr3xru44hfnta",
},
},
},
},
},
},
}

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