@@ -729,8 +729,18 @@ func TestResyncUsingDCPStream(t *testing.T) {
729729 resyncManagerStatus := rt .WaitForResyncDCPStatus (db .BackgroundProcessStateCompleted )
730730
731731 assert .Equal (t , testCase .docsCreated , int (rt .GetDatabase ().DbStats .Database ().SyncFunctionCount .Value ()))
732-
733- assert .Equal (t , testCase .docsCreated , int (resyncManagerStatus .DocsProcessed ))
732+ if ! base .UnitTestUrlIsWalrus () && ! base .TestsDisableGSI () {
733+ // It is possible for Couchbase Server GSI runs which use DCP purge to two DCP events from a previous
734+ // test.
735+ // 1. doc1 mutation
736+ // 2. doc1 deletion
737+ //
738+ // In a test, these will not be resynced but docsProcessed is incremented. Relax
739+ // the assertion to greater than the number of documents.
740+ assert .GreaterOrEqual (t , int (resyncManagerStatus .DocsProcessed ), testCase .docsCreated )
741+ } else {
742+ assert .Equal (t , testCase .docsCreated , int (resyncManagerStatus .DocsProcessed ))
743+ }
734744 assert .Equal (t , 0 , int (resyncManagerStatus .DocsChanged ))
735745 })
736746 }
@@ -784,8 +794,19 @@ func TestResyncUsingDCPStreamReset(t *testing.T) {
784794 assert .NotEqual (t , resyncID , resyncManagerStatus .ResyncID )
785795
786796 resyncManagerStatus = rt .WaitForResyncDCPStatus (db .BackgroundProcessStateCompleted )
787- assert .Equal (t , int64 (numDocs ), resyncManagerStatus .DocsProcessed )
797+ if ! base .UnitTestUrlIsWalrus () && ! base .TestsDisableGSI () {
798+ // It is possible for Couchbase Server GSI runs which use DCP purge to two DCP events from a previous
799+ // test.
800+ // 1. doc1 mutation
801+ // 2. doc1 deletion
802+ //
803+ // In a test, these will not be resynced but docsProcessed is incremented. Relax
804+ // the assertion to greater than the number of documents.
805+ assert .GreaterOrEqual (t , int (resyncManagerStatus .DocsProcessed ), numDocs )
806+ } else {
788807
808+ assert .Equal (t , int64 (numDocs ), resyncManagerStatus .DocsProcessed )
809+ }
789810}
790811
791812func TestResyncUsingDCPStreamForNamedCollection (t * testing.T ) {
@@ -804,12 +825,14 @@ func TestResyncUsingDCPStreamForNamedCollection(t *testing.T) {
804825
805826 rt := rest .NewRestTesterMultipleCollections (t ,
806827 & rest.RestTesterConfig {
807- SyncFn : syncFn ,
828+ SyncFn : syncFn ,
829+ PersistentConfig : true ,
808830 },
809831 numCollections ,
810832 )
811833 defer rt .Close ()
812834
835+ rest .RequireStatus (t , rt .CreateDatabase ("db" , rt .NewDbConfig ()), http .StatusCreated )
813836 // put a docs in both collections
814837 for i := 1 ; i <= 10 ; i ++ {
815838 resp := rt .SendAdminRequest (http .MethodPut , fmt .Sprintf ("/{{.keyspace1}}/1000%d" , i ), `{"type":"test_doc"}` )
@@ -821,6 +844,8 @@ func TestResyncUsingDCPStreamForNamedCollection(t *testing.T) {
821844
822845 rt .TakeDbOffline ()
823846
847+ rest .RequireStatus (t , rt .SendAdminRequest (http .MethodPut , "/{{.keyspace1}}/_config/sync" , `function(doc){channel("A")}` ), http .StatusOK )
848+ rest .RequireStatus (t , rt .SendAdminRequest (http .MethodPut , "/{{.keyspace2}}/_config/sync" , `function(doc){channel("A")}` ), http .StatusOK )
824849 dataStore1 , err := rt .TestBucket .GetNamedDataStore (0 )
825850 require .NoError (t , err )
826851 // Run resync for single collection // Request body {"scopes": "scopeName": ["collection1Name", "collection2Name"]}}
@@ -833,16 +858,17 @@ func TestResyncUsingDCPStreamForNamedCollection(t *testing.T) {
833858 rest .RequireStatus (t , resp , http .StatusOK )
834859 resyncManagerStatus := rt .WaitForResyncDCPStatus (db .BackgroundProcessStateCompleted )
835860
836- assert .Equal (t , 0 , int (resyncManagerStatus .DocsChanged ))
837- assert .LessOrEqual (t , 10 , int (resyncManagerStatus .DocsProcessed ))
861+ assert .Equal (t , 10 , int (resyncManagerStatus .DocsChanged ))
862+
863+ rest .RequireStatus (t , rt .SendAdminRequest (http .MethodPut , "/{{.keyspace1}}/_config/sync" , `function(doc){channel("B")}` ), http .StatusOK )
864+ rest .RequireStatus (t , rt .SendAdminRequest (http .MethodPut , "/{{.keyspace2}}/_config/sync" , `function(doc){channel("B")}` ), http .StatusOK )
838865
839866 // Run resync for all collections
840867 resp = rt .SendAdminRequest ("POST" , "/db/_resync?action=start" , "" )
841868 rest .RequireStatus (t , resp , http .StatusOK )
842869 resyncManagerStatus = rt .WaitForResyncDCPStatus (db .BackgroundProcessStateCompleted )
843870
844- assert .Equal (t , 0 , int (resyncManagerStatus .DocsChanged ))
845- assert .LessOrEqual (t , 20 , int (resyncManagerStatus .DocsProcessed ))
871+ assert .Equal (t , 20 , int (resyncManagerStatus .DocsChanged ))
846872}
847873
848874func TestResyncErrorScenariosUsingDCPStream (t * testing.T ) {
@@ -1230,6 +1256,7 @@ func TestMultipleBucketWithBadDbConfigScenario2(t *testing.T) {
12301256// - persist that db config to another bucket
12311257// - assert that is picked up as an invalid db config
12321258func TestMultipleBucketWithBadDbConfigScenario3 (t * testing.T ) {
1259+ base .RequireNumTestBuckets (t , 2 )
12331260
12341261 ctx := base .TestCtx (t )
12351262 tb1 := base .GetTestBucket (t )
@@ -3742,12 +3769,14 @@ func TestDeleteDatabaseCBGTTeardown(t *testing.T) {
37423769
37433770func TestDatabaseCreationErrorCode (t * testing.T ) {
37443771 for _ , persistentConfig := range []bool {true , false } {
3745- rt := rest .NewRestTester (t , & rest.RestTesterConfig {PersistentConfig : persistentConfig })
3746- defer rt .Close ()
3772+ t .Run (fmt .Sprintf ("persistent_config=%t" , persistentConfig ), func (t * testing.T ) {
3773+ rt := rest .NewRestTester (t , & rest.RestTesterConfig {PersistentConfig : persistentConfig })
3774+ defer rt .Close ()
37473775
3748- rt .CreateDatabase ("db" , rt .NewDbConfig ())
3749- resp := rt .SendAdminRequest (http .MethodPut , "/db/" , `{"bucket": "irrelevant"}` )
3750- rest .RequireStatus (t , resp , http .StatusPreconditionFailed )
3776+ rt .CreateDatabase ("db" , rt .NewDbConfig ())
3777+ resp := rt .SendAdminRequest (http .MethodPut , "/db/" , `{"bucket": "irrelevant"}` )
3778+ rest .RequireStatus (t , resp , http .StatusPreconditionFailed )
3779+ })
37513780 }
37523781}
37533782
0 commit comments