@@ -5858,7 +5858,6 @@ func TestActiveReplicatorPullConflictReadWriteIntlProps(t *testing.T) {
58585858func TestSGR2TombstoneConflictHandling (t * testing.T ) {
58595859
58605860 base .RequireNumTestBuckets (t , 2 )
5861- t .Skip ("CBG-4782: needs rework for version vectors, may be able ot get to work after rev tree reconciliation is done" )
58625861
58635862 tombstoneTests := []struct {
58645863 name string
@@ -5936,24 +5935,17 @@ func TestSGR2TombstoneConflictHandling(t *testing.T) {
59365935 }
59375936 }
59385937
5939- for _ , test := range tombstoneTests {
5940-
5941- t .Run (test .name , func (t * testing.T ) {
5942- if test .sdkResurrect && ! base .TestUseXattrs () {
5943- t .Skip ("SDK resurrect test cases require xattrs to be enabled" )
5944- }
5945-
5946- remotePassiveRT := rest .NewRestTester (t , nil )
5947- defer remotePassiveRT .Close ()
5948-
5949- // Active
5950- localActiveRT := rest .NewRestTester (t ,
5951- & rest.RestTesterConfig {
5952- SgReplicateEnabled : true ,
5953- })
5954- defer localActiveRT .Close ()
5938+ sgrRunner := rest .NewSGRTestRunner (t )
5939+ // tests is putting document rev trees in certain states, not fully relevant for v4 replication so keep in v3 mode
5940+ sgrRunner .RunSubprotocolV3 (func (t * testing.T ) {
5941+ for _ , test := range tombstoneTests {
5942+ t .Run (test .name , func (t * testing.T ) {
5943+ if test .sdkResurrect && ! base .TestUseXattrs () {
5944+ t .Skip ("SDK resurrect test cases require xattrs to be enabled" )
5945+ }
5946+ localActiveRT , remotePassiveRT , _ := sgrRunner .SetupSGRPeers (t )
59555947
5956- replConf := `
5948+ replConf := `
59575949 {
59585950 "replication_id": "replication",
59595951 "remote": "` + adminDBURL (remotePassiveRT ).String () + `",
@@ -5962,122 +5954,124 @@ func TestSGR2TombstoneConflictHandling(t *testing.T) {
59625954 "collections_enabled": ` + strconv .FormatBool (! localActiveRT .GetDatabase ().OnlyDefaultCollection ()) + `
59635955 }`
59645956
5965- // Send up replication
5966- resp := localActiveRT .SendAdminRequest ("PUT" , "/{{.db}}/_replication/replication" , replConf )
5967- rest .RequireStatus (t , resp , http .StatusCreated )
5968-
5969- // Create a doc with 3-revs
5970- resp = localActiveRT .SendAdminRequest ("POST" , "/{{.keyspace}}/_bulk_docs" , `{"docs":[{"_id": "docid2", "_rev": "1-abc"}, {"_id": "docid2", "_rev": "2-abc", "_revisions": {"start": 2, "ids": ["abc", "abc"]}}, {"_id": "docid2", "_rev": "3-abc", "val":"test", "_revisions": {"start": 3, "ids": ["abc", "abc", "abc"]}}], "new_edits":false}` )
5971- rest .RequireStatus (t , resp , http .StatusCreated )
5957+ // Send up replication
5958+ resp := localActiveRT .SendAdminRequest ("PUT" , "/{{.db}}/_replication/replication" , replConf )
5959+ rest .RequireStatus (t , resp , http .StatusCreated )
59725960
5973- // Wait for the replication to be started
5974- localActiveRT .WaitForReplicationStatus ("replication" , db .ReplicationStateRunning )
5961+ // Create a doc with 3-revs
5962+ resp = localActiveRT .SendAdminRequest ("POST" , "/{{.keyspace}}/_bulk_docs" , `{"docs":[{"_id": "docid2", "_rev": "1-abc"}, {"_id": "docid2", "_rev": "2-abc", "_revisions": {"start": 2, "ids": ["abc", "abc"]}}, {"_id": "docid2", "_rev": "3-abc", "val":"test", "_revisions": {"start": 3, "ids": ["abc", "abc", "abc"]}}], "new_edits":false}` )
5963+ rest .RequireStatus (t , resp , http .StatusCreated )
59755964
5976- const doc2ID = "docid2"
5977- doc2Version := rest.DocVersion {RevTreeID : "3-abc" }
5978- localActiveRT .WaitForVersion (doc2ID , doc2Version )
5979- remotePassiveRT .WaitForVersion (doc2ID , doc2Version )
5965+ // Wait for the replication to be started
5966+ localActiveRT .WaitForReplicationStatus ("replication" , db .ReplicationStateRunning )
59805967
5981- // Stop the replication
5982- rest .RequireStatus (t , localActiveRT .SendAdminRequest ("PUT" , "/{{.db}}/_replicationStatus/replication?action=stop" , "" ), http .StatusOK )
5983- localActiveRT .WaitForReplicationStatus ("replication" , db .ReplicationStateStopped )
5968+ const doc2ID = "docid2"
5969+ doc2Version := rest.DocVersion {RevTreeID : "3-abc" }
5970+ sgrRunner .WaitForVersion (doc2ID , localActiveRT , doc2Version )
5971+ sgrRunner .WaitForVersion (doc2ID , remotePassiveRT , doc2Version )
59845972
5985- // Delete on the short branch and make another doc on the longer branch before deleting it
5986- if test .longestBranchLocal {
5987- // Delete doc on remote
5988- deletedVersion := remotePassiveRT .DeleteDoc (doc2ID , doc2Version )
5989- require .Equal (t , "4-cc0337d9d38c8e5fc930ae3deda62bf8" , deletedVersion .RevTreeID )
5973+ // Stop the replication
5974+ rest .RequireStatus (t , localActiveRT .SendAdminRequest ("PUT" , "/{{.db}}/_replicationStatus/replication?action=stop" , "" ), http .StatusOK )
5975+ localActiveRT .WaitForReplicationStatus ("replication" , db .ReplicationStateStopped )
59905976
5991- // Create another rev and then delete doc on local - ie tree is longer
5992- version := localActiveRT .UpdateDoc (doc2ID , doc2Version , `{"foo":"bar"}` )
5993- localActiveRT .DeleteDoc (doc2ID , version )
5977+ // Delete on the short branch and make another doc on the longer branch before deleting it
5978+ deleteVersion := rest.DocVersion {}
5979+ if test .longestBranchLocal {
5980+ // Delete doc on remote
5981+ deletedVersion := remotePassiveRT .DeleteDoc (doc2ID , doc2Version )
5982+ require .Equal (t , "4-cc0337d9d38c8e5fc930ae3deda62bf8" , deletedVersion .RevTreeID )
59945983
5995- // Validate local is CBS tombstone, expect not found error
5996- // Expect KeyNotFound error retrieving local tombstone pre-replication
5997- requireTombstone ( t , localActiveRT .GetSingleDataStore (), "docid2" )
5984+ // Create another rev and then delete doc on local - ie tree is longer
5985+ version := localActiveRT . UpdateDoc ( doc2ID , doc2Version , `{"foo":"bar"}` )
5986+ deleteVersion = localActiveRT .DeleteDoc ( doc2ID , version )
59985987
5999- } else {
6000- // Delete doc on localActiveRT (active / local)
6001- deletedVersion := localActiveRT .DeleteDoc (doc2ID , doc2Version )
6002- require .Equal (t , "4-cc0337d9d38c8e5fc930ae3deda62bf8" , deletedVersion .RevTreeID )
5988+ // Validate local is CBS tombstone, expect not found error
5989+ // Expect KeyNotFound error retrieving local tombstone pre-replication
5990+ requireTombstone (t , localActiveRT .GetSingleDataStore (), "docid2" )
60035991
6004- // Create another rev and then delete doc on remotePassiveRT (passive) - ie, tree is longer
6005- version := remotePassiveRT .UpdateDoc (doc2ID , rest.DocVersion {RevTreeID : "3-abc" }, `{"foo":"bar"}` )
6006- remotePassiveRT .DeleteDoc (doc2ID , version )
5992+ } else {
5993+ // Delete doc on localActiveRT (active / local)
5994+ deletedVersion := localActiveRT .DeleteDoc (doc2ID , doc2Version )
5995+ require .Equal (t , "4-cc0337d9d38c8e5fc930ae3deda62bf8" , deletedVersion .RevTreeID )
60075996
6008- // Validate local is CBS tombstone, expect not found error
6009- // Expect KeyNotFound error retrieving remote tombstone pre-replication
6010- requireTombstone (t , remotePassiveRT .GetSingleDataStore (), doc2ID )
6011- }
5997+ // Create another rev and then delete doc on remotePassiveRT (passive) - ie, tree is longer
5998+ version := remotePassiveRT .UpdateDoc (doc2ID , rest.DocVersion {RevTreeID : "3-abc" }, `{"foo":"bar"}` )
5999+ deleteVersion = remotePassiveRT .DeleteDoc (doc2ID , version )
60126000
6013- // Start up repl again
6014- rest .RequireStatus (t , localActiveRT .SendAdminRequest ("PUT" , "/{{.db}}/_replicationStatus/replication?action=start" , "" ), http .StatusOK )
6015- localActiveRT .WaitForReplicationStatus ("replication" , db .ReplicationStateRunning )
6001+ // Validate local is CBS tombstone, expect not found error
6002+ // Expect KeyNotFound error retrieving remote tombstone pre-replication
6003+ requireTombstone (t , remotePassiveRT .GetSingleDataStore (), doc2ID )
6004+ }
60166005
6017- // Wait for the recently longest branch to show up on both sides
6018- localActiveRT . WaitForTombstone ( doc2ID , rest. DocVersion { RevTreeID : "5-4a5f5a35196c37c117737afd5be1fc9b" } )
6019- remotePassiveRT . WaitForTombstone ( doc2ID , rest. DocVersion { RevTreeID : "5-4a5f5a35196c37c117737afd5be1fc9b" } )
6006+ // Start up repl again
6007+ rest . RequireStatus ( t , localActiveRT . SendAdminRequest ( "PUT" , "/{{.db}}/_replicationStatus/replication?action=start" , "" ), http . StatusOK )
6008+ localActiveRT . WaitForReplicationStatus ( "replication" , db . ReplicationStateRunning )
60206009
6021- // Stop the replication
6022- rest . RequireStatus ( t , localActiveRT . SendAdminRequest ( "PUT" , "/{{.db}}/_replicationStatus/replication?action=stop" , "" ), http . StatusOK )
6023- localActiveRT . WaitForReplicationStatus ( "replication" , db . ReplicationStateStopped )
6010+ // Wait for the recently longest branch to show up on both sides
6011+ sgrRunner . WaitForTombstone ( doc2ID , localActiveRT , deleteVersion )
6012+ sgrRunner . WaitForTombstone ( doc2ID , remotePassiveRT , deleteVersion )
60246013
6025- // Resurrect Doc
6026- updatedBody := make (map [string ]interface {})
6027- updatedBody ["resurrection" ] = true
6028- if test .resurrectLocal {
6029- if test .sdkResurrect {
6030- // resurrect doc via SDK on local
6031- err := localActiveRT .GetSingleDataStore ().Set (doc2ID , 0 , nil , updatedBody )
6032- assert .NoError (t , err , "Unable to resurrect doc docid2" )
6033- collection , ctx := localActiveRT .GetSingleTestDatabaseCollection ()
6034- // force on-demand import
6035- _ , getErr := collection .GetDocument (ctx , "docid2" , db .DocUnmarshalSync )
6036- require .NoError (t , getErr , "Unable to retrieve resurrected doc docid2" )
6014+ // Stop the replication
6015+ rest .RequireStatus (t , localActiveRT .SendAdminRequest ("PUT" , "/{{.db}}/_replicationStatus/replication?action=stop" , "" ), http .StatusOK )
6016+ localActiveRT .WaitForReplicationStatus ("replication" , db .ReplicationStateStopped )
6017+
6018+ // Resurrect Doc
6019+ updatedBody := make (map [string ]interface {})
6020+ updatedBody ["resurrection" ] = true
6021+ if test .resurrectLocal {
6022+ if test .sdkResurrect {
6023+ // resurrect doc via SDK on local
6024+ err := localActiveRT .GetSingleDataStore ().Set (doc2ID , 0 , nil , updatedBody )
6025+ assert .NoError (t , err , "Unable to resurrect doc docid2" )
6026+ collection , ctx := localActiveRT .GetSingleTestDatabaseCollection ()
6027+ // force on-demand import
6028+ _ , getErr := collection .GetDocument (ctx , "docid2" , db .DocUnmarshalSync )
6029+ require .NoError (t , getErr , "Unable to retrieve resurrected doc docid2" )
6030+ } else {
6031+ localActiveRT .PutDoc ("docid2" , `{"resurrection": true}` )
6032+ }
60376033 } else {
6038- localActiveRT .PutDoc ("docid2" , `{"resurrection": true}` )
6034+ if test .sdkResurrect {
6035+ // resurrect doc via SDK on remote
6036+ err := remotePassiveRT .GetSingleDataStore ().Set (doc2ID , 0 , nil , updatedBody )
6037+ assert .NoError (t , err , "Unable to resurrect doc docid2" )
6038+ // force on-demand import
6039+ collection , ctx := remotePassiveRT .GetSingleTestDatabaseCollection ()
6040+ _ , getErr := collection .GetDocument (ctx , doc2ID , db .DocUnmarshalSync )
6041+ assert .NoError (t , getErr , "Unable to retrieve resurrected doc docid2" )
6042+ } else {
6043+ remotePassiveRT .PutDoc ("docid2" , `{"resurrection": true}` )
6044+ }
60396045 }
6040- } else {
6046+
6047+ // For SG resurrect, rev history is preserved, expect rev 6-...
6048+ expectedRevID := "6-bf187e11c1f8913769dca26e56621036"
60416049 if test .sdkResurrect {
6042- // resurrect doc via SDK on remote
6043- err := remotePassiveRT .GetSingleDataStore ().Set (doc2ID , 0 , nil , updatedBody )
6044- assert .NoError (t , err , "Unable to resurrect doc docid2" )
6045- // force on-demand import
6046- collection , ctx := remotePassiveRT .GetSingleTestDatabaseCollection ()
6047- _ , getErr := collection .GetDocument (ctx , doc2ID , db .DocUnmarshalSync )
6048- assert .NoError (t , getErr , "Unable to retrieve resurrected doc docid2" )
6049- } else {
6050- remotePassiveRT .PutDoc ("docid2" , `{"resurrection": true}` )
6050+ // For SDK resurrect, rev history is not preserved, expect rev 1-...
6051+ expectedRevID = "1-e5d43a9cdc4a2d4e258800dfc37e9d77"
60516052 }
6052- }
60536053
6054- // For SG resurrect, rev history is preserved, expect rev 6-...
6055- expectedRevID := "6-bf187e11c1f8913769dca26e56621036"
6056- if test .sdkResurrect {
6057- // For SDK resurrect, rev history is not preserved, expect rev 1-...
6058- expectedRevID = "1-e5d43a9cdc4a2d4e258800dfc37e9d77"
6059- }
6060-
6061- expectedVersion := rest.DocVersion {RevTreeID : expectedRevID }
6062- // Wait for doc to show up on side that the resurrection was done
6063- if test .resurrectLocal {
6064- localActiveRT .WaitForVersion (doc2ID , expectedVersion )
6065- } else {
6066- remotePassiveRT .WaitForVersion (doc2ID , expectedVersion )
6067- }
6054+ expectedVersion := rest.DocVersion {RevTreeID : expectedRevID }
6055+ // Wait for doc to show up on side that the resurrection was done
6056+ if test .resurrectLocal {
6057+ localActiveRT .WaitForVersion (doc2ID , expectedVersion )
6058+ } else {
6059+ remotePassiveRT .WaitForVersion (doc2ID , expectedVersion )
6060+ }
60686061
6069- // Start the replication
6070- rest .RequireStatus (t , localActiveRT .SendAdminRequest ("PUT" , "/{{.db}}/_replicationStatus/replication?action=start" , "" ), http .StatusOK )
6071- localActiveRT .WaitForReplicationStatus ("replication" , db .ReplicationStateRunning )
6062+ // Start the replication
6063+ rest .RequireStatus (t , localActiveRT .SendAdminRequest ("PUT" , "/{{.db}}/_replicationStatus/replication?action=start" , "" ), http .StatusOK )
6064+ localActiveRT .WaitForReplicationStatus ("replication" , db .ReplicationStateRunning )
60726065
6073- // Wait for doc to replicate from side resurrection was done on to the other side
6074- if test .resurrectLocal {
6075- remotePassiveRT .WaitForVersion (doc2ID , expectedVersion )
6076- } else {
6077- localActiveRT .WaitForVersion (doc2ID , expectedVersion )
6078- }
6079- })
6080- }
6066+ // Wait for doc to replicate from side resurrection was done on to the other side
6067+ if test .resurrectLocal {
6068+ remotePassiveRT .WaitForVersion (doc2ID , expectedVersion )
6069+ } else {
6070+ localActiveRT .WaitForVersion (doc2ID , expectedVersion )
6071+ }
6072+ })
6073+ }
6074+ })
60816075}
60826076
60836077// This test ensures that the local tombstone revision wins over non-tombstone revision
0 commit comments