forked from cockroachdb/cockroach
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rangefeedcache: handle auth error in initial scan
Previously, if the rangfeedcache.Watcher ran into an auth error, it was never reported to the caller. This was detected as part of cockroachdb#97991. Moving the settingswatcher to be the first component initialized in the sql server caused the TestTenantUnauthenticatedAccess test to fail. Now, the error is reported to the caller and rebasing cockroachdb#97991 on top of this change allows the test to pass. Part of cockroachdb#94843 Release note: None
- Loading branch information
1 parent
cd80204
commit 8166c88
Showing
3 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// Copyright 2023 The Cockroach Authors. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.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/APL.txt. | ||
|
||
package rangefeedcache_test | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/cockroachdb/cockroach/pkg/base" | ||
"github.com/cockroachdb/cockroach/pkg/ccl/kvccl/kvtenantccl" | ||
"github.com/cockroachdb/cockroach/pkg/kv/kvclient/rangefeed" | ||
"github.com/cockroachdb/cockroach/pkg/kv/kvclient/rangefeed/rangefeedbuffer" | ||
"github.com/cockroachdb/cockroach/pkg/kv/kvclient/rangefeed/rangefeedcache" | ||
"github.com/cockroachdb/cockroach/pkg/kv/kvpb" | ||
"github.com/cockroachdb/cockroach/pkg/roachpb" | ||
"github.com/cockroachdb/cockroach/pkg/testutils/serverutils" | ||
"github.com/cockroachdb/cockroach/pkg/util/grpcutil" | ||
"github.com/cockroachdb/cockroach/pkg/util/leaktest" | ||
"github.com/cockroachdb/cockroach/pkg/util/log" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestWatchAuthErr(t *testing.T) { | ||
defer leaktest.AfterTest(t)() | ||
defer log.Scope(t).Close(t) | ||
|
||
ctx := context.Background() | ||
host, _, _ := serverutils.StartServer(t, base.TestServerArgs{}) | ||
defer host.Stopper().Stop(ctx) | ||
|
||
var _ = kvtenantccl.Connector{} | ||
tenant, _ := serverutils.StartTenant(t, host, base.TestTenantArgs{ | ||
TenantID: serverutils.TestTenantID(), | ||
}) | ||
|
||
hostScratchRange, err := host.ScratchRange() | ||
require.NoError(t, err) | ||
hostScratchSpan := roachpb.Span{ | ||
Key: hostScratchRange, | ||
EndKey: hostScratchRange.PrefixEnd(), | ||
} | ||
|
||
w := rangefeedcache.NewWatcher( | ||
"test", | ||
tenant.Clock(), | ||
tenant.RangeFeedFactory().(*rangefeed.Factory), | ||
1024, | ||
[]roachpb.Span{hostScratchSpan}, | ||
false, /*=withPrevValue*/ | ||
func(ctx context.Context, kv *kvpb.RangeFeedValue) rangefeedbuffer.Event { | ||
t.Fatalf("rangefeed should fail before producing results") | ||
return nil | ||
}, | ||
func(ctx context.Context, update rangefeedcache.Update) { | ||
t.Fatalf("rangefeed should fail before producing results") | ||
}, | ||
&rangefeedcache.TestingKnobs{}) | ||
|
||
err = w.Run(ctx) | ||
require.True(t, grpcutil.IsAuthError(err), "expected %v to be an auth error", err) | ||
} |