diff --git a/db/database_test.go b/db/database_test.go index 31727d5a58..0bf33b012e 100644 --- a/db/database_test.go +++ b/db/database_test.go @@ -1389,11 +1389,12 @@ func TestSyncFnOnPush(t *testing.T) { // Check that the doc has the correct channel (test for issue #300) doc, err := collection.GetDocument(ctx, "doc1", DocUnmarshalAll) assert.Equal(t, channels.ChannelMap{ + "*": nil, "clibup": nil, "public": &channels.ChannelRemoval{Seq: 2, RevID: "4-four"}, }, doc.Channels) - assert.Equal(t, base.SetOf("clibup"), doc.History["4-four"].Channels) + assert.Equal(t, base.SetOf("*", "clibup"), doc.History["4-four"].Channels) } func TestInvalidChannel(t *testing.T) { @@ -2456,7 +2457,7 @@ func TestResyncUpdateAllDocChannels(t *testing.T) { return state == DBOffline }) - _, err = collection.UpdateAllDocChannels(ctx, false, func(docsProcessed, docsChanged *int) {}, base.NewSafeTerminator(), false) + _, err = collection.UpdateAllDocChannels(ctx, false, func(docsProcessed, docsChanged *int) {}, base.NewSafeTerminator(), !db.AllDocsIndexExists) assert.NoError(t, err) syncFnCount := int(db.DbStats.Database().SyncFunctionCount.Value()) diff --git a/rest/adminapitest/admin_api_test.go b/rest/adminapitest/admin_api_test.go index 01b6f65071..ec3c60e6a1 100644 --- a/rest/adminapitest/admin_api_test.go +++ b/rest/adminapitest/admin_api_test.go @@ -888,8 +888,8 @@ func TestRawRedaction(t *testing.T) { err := base.JSONUnmarshal(res.Body.Bytes(), &body) assert.NoError(t, err) syncData := body[base.SyncPropertyName] - assert.Equal(t, map[string]interface{}{"achannel": nil}, syncData.(map[string]interface{})["channels"]) - assert.Equal(t, []interface{}([]interface{}{[]interface{}{"achannel"}}), syncData.(map[string]interface{})["history"].(map[string]interface{})["channels"]) + assert.Equal(t, map[string]interface{}{"achannel": nil, "*": nil}, syncData.(map[string]interface{})["channels"]) + assert.Equal(t, []interface{}([]interface{}{[]interface{}{"*", "achannel"}}), syncData.(map[string]interface{})["history"].(map[string]interface{})["channels"]) // Test redacted body = map[string]interface{}{} diff --git a/rest/api_test.go b/rest/api_test.go index 5c31394cae..02a6d4ef36 100644 --- a/rest/api_test.go +++ b/rest/api_test.go @@ -2407,9 +2407,18 @@ func TestDocumentChannelHistory(t *testing.T) { syncData, err := rt.GetDatabase().GetSingleDatabaseCollection().GetDocSyncData(base.TestCtx(t), "doc") assert.NoError(t, err) - require.Len(t, syncData.ChannelSet, 1) - assert.Equal(t, syncData.ChannelSet[0], db.ChannelSetEntry{Name: "test", Start: 1, End: 0}) - assert.Len(t, syncData.ChannelSetHistory, 0) + shouldExpectStarChannel := !rt.GetDatabase().AllDocsIndexExists + + if shouldExpectStarChannel { + require.Len(t, syncData.ChannelSet, 2) + assert.Contains(t, syncData.ChannelSet, db.ChannelSetEntry{Name: "test", Start: 1, End: 0}) + assert.Contains(t, syncData.ChannelSet, db.ChannelSetEntry{Name: "*", Start: 1, End: 0}) + assert.Len(t, syncData.ChannelSetHistory, 0) + } else { + require.Len(t, syncData.ChannelSet, 1) + assert.Equal(t, syncData.ChannelSet[0], db.ChannelSetEntry{Name: "test", Start: 1, End: 0}) + assert.Len(t, syncData.ChannelSetHistory, 0) + } // Update doc to remove from channel and ensure a single channel history entry with both start and end sequences // and no old channel history entries @@ -2420,9 +2429,16 @@ func TestDocumentChannelHistory(t *testing.T) { syncData, err = rt.GetDatabase().GetSingleDatabaseCollection().GetDocSyncData(base.TestCtx(t), "doc") assert.NoError(t, err) - require.Len(t, syncData.ChannelSet, 1) - assert.Equal(t, syncData.ChannelSet[0], db.ChannelSetEntry{Name: "test", Start: 1, End: 2}) - assert.Len(t, syncData.ChannelSetHistory, 0) + if shouldExpectStarChannel { + require.Len(t, syncData.ChannelSet, 2) + assert.Contains(t, syncData.ChannelSet, db.ChannelSetEntry{Name: "test", Start: 1, End: 2}) + assert.Contains(t, syncData.ChannelSet, db.ChannelSetEntry{Name: "*", Start: 1, End: 0}) + assert.Len(t, syncData.ChannelSetHistory, 0) + } else { + require.Len(t, syncData.ChannelSet, 1) + assert.Equal(t, syncData.ChannelSet[0], db.ChannelSetEntry{Name: "test", Start: 1, End: 2}) + assert.Len(t, syncData.ChannelSetHistory, 0) + } // Update doc to add to channels test and test2 and ensure a single channel history entry for both test and test2 // both with start sequences only and ensure old test entry was moved to old @@ -2433,11 +2449,19 @@ func TestDocumentChannelHistory(t *testing.T) { syncData, err = rt.GetDatabase().GetSingleDatabaseCollection().GetDocSyncData(base.TestCtx(t), "doc") assert.NoError(t, err) - require.Len(t, syncData.ChannelSet, 2) - assert.Contains(t, syncData.ChannelSet, db.ChannelSetEntry{Name: "test", Start: 3, End: 0}) - assert.Contains(t, syncData.ChannelSet, db.ChannelSetEntry{Name: "test2", Start: 3, End: 0}) - require.Len(t, syncData.ChannelSetHistory, 1) - assert.Equal(t, syncData.ChannelSetHistory[0], db.ChannelSetEntry{Name: "test", Start: 1, End: 2}) + if shouldExpectStarChannel { + require.Len(t, syncData.ChannelSet, 3) + assert.Contains(t, syncData.ChannelSet, db.ChannelSetEntry{Name: "test", Start: 3, End: 0}) + assert.Contains(t, syncData.ChannelSet, db.ChannelSetEntry{Name: "test2", Start: 3, End: 0}) + require.Len(t, syncData.ChannelSetHistory, 1) + assert.Equal(t, syncData.ChannelSetHistory[0], db.ChannelSetEntry{Name: "test", Start: 1, End: 2}) + } else { + require.Len(t, syncData.ChannelSet, 2) + assert.Contains(t, syncData.ChannelSet, db.ChannelSetEntry{Name: "test", Start: 3, End: 0}) + assert.Contains(t, syncData.ChannelSet, db.ChannelSetEntry{Name: "test2", Start: 3, End: 0}) + require.Len(t, syncData.ChannelSetHistory, 1) + assert.Equal(t, syncData.ChannelSetHistory[0], db.ChannelSetEntry{Name: "test", Start: 1, End: 2}) + } } func TestChannelHistoryLegacyDoc(t *testing.T) { @@ -2497,7 +2521,11 @@ func TestChannelHistoryLegacyDoc(t *testing.T) { assert.NoError(t, err) syncData, err := rt.GetDatabase().GetSingleDatabaseCollection().GetDocSyncData(base.TestCtx(t), "doc1") assert.NoError(t, err) - require.Len(t, syncData.ChannelSet, 1) + if rt.GetDatabase().AllDocsIndexExists { + require.Len(t, syncData.ChannelSet, 1) + } else { + require.Len(t, syncData.ChannelSet, 2) + } assert.Contains(t, syncData.ChannelSet, db.ChannelSetEntry{ Name: "test", Start: 1, diff --git a/rest/doc_api_test.go b/rest/doc_api_test.go index c19f15f98c..04c2e6cf38 100644 --- a/rest/doc_api_test.go +++ b/rest/doc_api_test.go @@ -105,6 +105,8 @@ func TestDocumentNumbers(t *testing.T) { base.SetUpTestLogging(t, base.LevelDebug, base.KeyAll) + shouldExpectStarChannel := !rt.GetDatabase().AllDocsIndexExists + for _, test := range tests { t.Run(test.name, func(ts *testing.T) { // Create document @@ -126,7 +128,11 @@ func TestDocumentNumbers(t *testing.T) { var rawResponse RawResponse require.NoError(ts, base.JSONUnmarshal(getRawResponse.Body.Bytes(), &rawResponse)) log.Printf("raw response: %s", getRawResponse.Body.Bytes()) - assert.Equal(ts, 1, len(rawResponse.Sync.Channels)) + if shouldExpectStarChannel { + assert.Equal(ts, 2, len(rawResponse.Sync.Channels)) + } else { + assert.Equal(ts, 1, len(rawResponse.Sync.Channels)) + } assert.True(ts, HasActiveChannel(rawResponse.Sync.Channels, test.expectedFormatChannel), fmt.Sprintf("Expected channel %s was not found in document channels (%s)", test.expectedFormatChannel, test.name)) }) diff --git a/rest/sync_fn_test.go b/rest/sync_fn_test.go index 8b8588c402..db0e7f15f9 100644 --- a/rest/sync_fn_test.go +++ b/rest/sync_fn_test.go @@ -42,6 +42,7 @@ func TestSyncFnBodyProperties(t *testing.T) { testdataKey, db.BodyId, db.BodyRev, + "*", } // This sync function routes into channels based on top-level properties contained in doc @@ -84,6 +85,7 @@ func TestSyncFnBodyPropertiesTombstone(t *testing.T) { db.BodyId, db.BodyRev, db.BodyDeleted, + "*", } // This sync function routes into channels based on top-level properties contained in doc @@ -131,6 +133,7 @@ func TestSyncFnOldDocBodyProperties(t *testing.T) { expectedProperties := []string{ testdataKey, db.BodyId, + "*", } // This sync function routes into channels based on top-level properties contained in oldDoc @@ -180,6 +183,7 @@ func TestSyncFnOldDocBodyPropertiesTombstoneResurrect(t *testing.T) { testdataKey, db.BodyId, db.BodyDeleted, + "*", } // This sync function routes into channels based on top-level properties contained in oldDoc