From 6f53af2b1e5c14c9de21d121548804e86c8ede84 Mon Sep 17 00:00:00 2001 From: AndrewSisley Date: Wed, 24 Jan 2024 17:15:02 -0500 Subject: [PATCH] test(i): Document doc sync before schema update bug (#2256) ## Relevant issue(s) Documents #2255 ## Description Documents a bug (very likely cache related) when a doc syncs to a node on an older schema version before the schema is updated. --- .../simple/peer/with_create_add_field_test.go | 89 +++++++++++++++++++ 1 file changed, 89 insertions(+) diff --git a/tests/integration/net/state/simple/peer/with_create_add_field_test.go b/tests/integration/net/state/simple/peer/with_create_add_field_test.go index 31861d6498..46ad3c5a9c 100644 --- a/tests/integration/net/state/simple/peer/with_create_add_field_test.go +++ b/tests/integration/net/state/simple/peer/with_create_add_field_test.go @@ -203,3 +203,92 @@ func TestP2PPeerCreateWithNewFieldSyncsDocsToUpdatedSchemaVersion(t *testing.T) testUtils.ExecuteTestCase(t, test) } + +// This test documents unwanted behaviour and should be changed when +// https://github.com/sourcenetwork/defradb/issues/2255 is fixed. +func TestP2PPeerCreateWithNewFieldDocSyncedBeforeReceivingNodeSchemaUpdatedDoesNotReturnNewField(t *testing.T) { + test := testUtils.TestCase{ + Actions: []any{ + testUtils.RandomNetworkingConfig(), + testUtils.RandomNetworkingConfig(), + testUtils.SchemaUpdate{ + Schema: ` + type Users { + Name: String + } + `, + }, + testUtils.ConnectPeers{ + SourceNodeID: 1, + TargetNodeID: 0, + }, + testUtils.SubscribeToCollection{ + NodeID: 1, + CollectionIDs: []int{0}, + }, + testUtils.SchemaPatch{ + // Patch the schema on the first node only + NodeID: immutable.Some(0), + Patch: ` + [ + { "op": "add", "path": "/Users/Fields/-", "value": {"Name": "Email", "Kind": 11} } + ] + `, + }, + testUtils.CreateDoc{ + // Create the doc with a value in the new field on the first node only, and allow the values to sync + NodeID: immutable.Some(0), + Doc: `{ + "Name": "John", + "Email": "imnotyourbuddyguy@source.ca" + }`, + }, + testUtils.WaitForSync{}, + testUtils.SchemaPatch{ + // Update the schema on the second node + NodeID: immutable.Some(1), + Patch: ` + [ + { "op": "add", "path": "/Users/Fields/-", "value": {"Name": "Email", "Kind": 11} } + ] + `, + }, + testUtils.Request{ + NodeID: immutable.Some(0), + Request: ` + query { + Users { + Name + Email + } + } + `, + Results: []map[string]any{ + { + "Name": "John", + "Email": "imnotyourbuddyguy@source.ca", + }, + }, + }, + testUtils.Request{ + NodeID: immutable.Some(1), + Request: ` + query { + Users { + Name + Email + } + } + `, + Results: []map[string]any{ + { + "Name": "John", + // The email should be returned but it is not + }, + }, + }, + }, + } + + testUtils.ExecuteTestCase(t, test) +}