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

move logging test to no race #6897

Merged
merged 1 commit into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
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
46 changes: 46 additions & 0 deletions rest/changestest/changes_api_no_race_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright 2012-Present Couchbase, Inc.
//
// Use of this software is governed by the Business Source License included
// in the file licenses/BSL-Couchbase.txt. As of the Change Date specified
// in that file, in accordance with the Business Source License, use of this
// software will be governed by the Apache License, Version 2.0, included in
// the file licenses/APL2.txt.

//go:build !race

package changestest

import (
"net/http"
"testing"

"github.com/couchbase/sync_gateway/base"
"github.com/couchbase/sync_gateway/db"
"github.com/couchbase/sync_gateway/rest"
"github.com/stretchr/testify/require"
)

// AssertLogContains can hit the race detector due to swapping the global loggers
// TestDocChangedLogging exercises some of the logging in DocChanged
func TestDocChangedLogging(t *testing.T) {
base.SetUpTestLogging(t, base.LevelDebug, base.KeyHTTP, base.KeyCache, base.KeyChanges)

rt := rest.NewRestTesterMultipleCollections(t, nil, 2)
defer rt.Close()

response := rt.SendAdminRequest("PUT", "/{{.keyspace1}}/doc1", `{"foo":"bar"}`)
rest.RequireStatus(t, response, http.StatusCreated)
response = rt.SendAdminRequest("PUT", "/{{.keyspace2}}/doc1", `{"foo":"bar"}`)
rest.RequireStatus(t, response, http.StatusCreated)
require.NoError(t, rt.WaitForPendingChanges())

base.AssertLogContains(t, "Ignoring non-metadata mutation for doc", func() {
err := rt.GetDatabase().MetadataStore.Set("doc1", 0, nil, db.Body{"foo": "bar"})
require.NoError(t, err)
// write another doc to ensure the previous non-metadata doc has been seen...
// no other way of synchronising this no-op as no stats to wait on
response = rt.SendAdminRequest("PUT", "/{{.keyspace1}}/doc2", `{"foo":"bar"}`)
rest.RequireStatus(t, response, http.StatusCreated)
require.NoError(t, rt.WaitForPendingChanges())
})
}
24 changes: 0 additions & 24 deletions rest/changestest/changes_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4399,27 +4399,3 @@ func WriteDirectWithKey(t *testing.T, key string, channelArray []string, sequenc
require.NoError(t, err)

}

// TestDocChangedLogging exercises some of the logging in DocChanged
func TestDocChangedLogging(t *testing.T) {
base.SetUpTestLogging(t, base.LevelDebug, base.KeyHTTP, base.KeyCache, base.KeyChanges)

rt := rest.NewRestTesterMultipleCollections(t, nil, 2)
defer rt.Close()

response := rt.SendAdminRequest("PUT", "/{{.keyspace1}}/doc1", `{"foo":"bar"}`)
rest.RequireStatus(t, response, http.StatusCreated)
response = rt.SendAdminRequest("PUT", "/{{.keyspace2}}/doc1", `{"foo":"bar"}`)
rest.RequireStatus(t, response, http.StatusCreated)
require.NoError(t, rt.WaitForPendingChanges())

base.AssertLogContains(t, "Ignoring non-metadata mutation for doc", func() {
err := rt.GetDatabase().MetadataStore.Set("doc1", 0, nil, db.Body{"foo": "bar"})
require.NoError(t, err)
// write another doc to ensure the previous non-metadata doc has been seen...
// no other way of synchronising this no-op as no stats to wait on
response = rt.SendAdminRequest("PUT", "/{{.keyspace1}}/doc2", `{"foo":"bar"}`)
rest.RequireStatus(t, response, http.StatusCreated)
require.NoError(t, rt.WaitForPendingChanges())
})
}
Loading