Skip to content

Commit d3cb135

Browse files
committed
sctest: pass around cluster settings instead of always generating new
Previously, the end_to_end test would always create a new set of cluster settings when spawning a subtest, causing cluster settings made during setup to be lost. This change causes subtests to inherit settings, retaining them. Release note: None
1 parent 7d65e38 commit d3cb135

File tree

4 files changed

+17
-0
lines changed

4 files changed

+17
-0
lines changed

pkg/sql/schemachanger/scdeps/sctestdeps/config.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package sctestdeps
88
import (
99
"time"
1010

11+
"github.com/cockroachdb/cockroach/pkg/settings/cluster"
1112
"github.com/cockroachdb/cockroach/pkg/sql/catalog"
1213
"github.com/cockroachdb/cockroach/pkg/sql/catalog/catalogkeys"
1314
"github.com/cockroachdb/cockroach/pkg/sql/catalog/descidgen"
@@ -166,6 +167,16 @@ func WithReferenceProviderFactory(f scbuild.ReferenceProviderFactory) Option {
166167
})
167168
}
168169

170+
func WithClusterSettings(cs *cluster.Settings) Option {
171+
return optionFunc(func(state *TestState) {
172+
state.clusterSettings = cs
173+
// Update evalCtx settings if it already exists
174+
if state.evalCtx != nil {
175+
state.evalCtx.Settings = cs
176+
}
177+
})
178+
}
179+
169180
var (
170181
// defaultOverriddenCreatedAt is used to populate the CreatedAt timestamp for
171182
// all descriptors injected into the catalog. We inject this to make the

pkg/sql/schemachanger/scdeps/sctestdeps/test_deps.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ func (s *TestState) SessionData() *sessiondata.SessionData {
8888

8989
// ClusterSettings implements the scbuild.Dependencies interface.
9090
func (s *TestState) ClusterSettings() *cluster.Settings {
91+
if s.clusterSettings != nil {
92+
return s.clusterSettings
93+
}
9194
return cluster.MakeTestingClusterSettings()
9295
}
9396

pkg/sql/schemachanger/scdeps/sctestdeps/test_state.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"github.com/cockroachdb/cockroach/pkg/jobs"
1616
"github.com/cockroachdb/cockroach/pkg/jobs/jobspb"
1717
"github.com/cockroachdb/cockroach/pkg/security/username"
18+
"github.com/cockroachdb/cockroach/pkg/settings/cluster"
1819
"github.com/cockroachdb/cockroach/pkg/sql/catalog"
1920
"github.com/cockroachdb/cockroach/pkg/sql/catalog/catalogkeys"
2021
"github.com/cockroachdb/cockroach/pkg/sql/catalog/descpb"
@@ -81,6 +82,7 @@ type TestState struct {
8182

8283
catalogChanges catalogChanges
8384
refProviderFactory scbuild.ReferenceProviderFactory
85+
clusterSettings *cluster.Settings
8486
}
8587

8688
type catalogChanges struct {

pkg/sql/schemachanger/sctest/end_to_end.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ func EndToEndSideEffects(t *testing.T, relTestCaseDir string, factory TestServer
153153
sctestdeps.WithComments(sctestdeps.ReadCommentsFromDB(t, tdb)),
154154
sctestdeps.WithIDGenerator(s.ApplicationLayer()),
155155
sctestdeps.WithReferenceProviderFactory(refFactory),
156+
sctestdeps.WithClusterSettings(s.ClusterSettings()),
156157
)
157158
stmtStates := execStatementWithTestDeps(ctx, t, deps, stmts...)
158159
var fileNameSuffix string

0 commit comments

Comments
 (0)