Skip to content

Commit b05b94d

Browse files
committed
scbuild: split TestBuildDataDriven into 2 tests
This will allow for better test sharding to avoid timeouts. Release note: None
1 parent e3770b8 commit b05b94d

File tree

1 file changed

+81
-71
lines changed

1 file changed

+81
-71
lines changed

pkg/sql/schemachanger/scbuild/builder_test.go

Lines changed: 81 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -44,86 +44,96 @@ import (
4444
"gopkg.in/yaml.v3"
4545
)
4646

47-
func TestBuildDataDriven(t *testing.T) {
47+
func TestBuildDataDrivenWithSQLDependencies(t *testing.T) {
4848
defer leaktest.AfterTest(t)()
4949
defer log.Scope(t).Close(t)
5050
defer ccl.TestingEnableEnterprise()() // allow usage of partitions and zone configs
5151

5252
ctx := context.Background()
5353

5454
skip.UnderRace(t, "expensive and can easily extend past test timeout")
55+
skip.UnderDeadlock(t, "expensive and can easily extend past test timeout")
56+
57+
dependenciesWrapper := func(t *testing.T, s serverutils.ApplicationLayerInterface, nodeID roachpb.NodeID, tdb *sqlutils.SQLRunner, fn func(scbuild.Dependencies)) {
58+
sctestutils.WithBuilderDependenciesFromTestServer(s, nodeID, fn)
59+
}
5560

5661
datadriven.Walk(t, datapathutils.TestDataPath(t), func(t *testing.T, path string) {
57-
for _, depsType := range []struct {
58-
name string
59-
dependenciesWrapper func(*testing.T, serverutils.ApplicationLayerInterface, roachpb.NodeID, *sqlutils.SQLRunner, func(scbuild.Dependencies))
60-
}{
61-
{
62-
name: "sql_dependencies",
63-
dependenciesWrapper: func(t *testing.T, s serverutils.ApplicationLayerInterface, nodeID roachpb.NodeID, tdb *sqlutils.SQLRunner, fn func(scbuild.Dependencies)) {
64-
sctestutils.WithBuilderDependenciesFromTestServer(s, nodeID, fn)
65-
},
66-
},
67-
{
68-
name: "test_dependencies",
69-
dependenciesWrapper: func(t *testing.T, s serverutils.ApplicationLayerInterface, nodeID roachpb.NodeID, tdb *sqlutils.SQLRunner, fn func(scbuild.Dependencies)) {
70-
// Create test dependencies and execute the schema changer.
71-
// The schema changer test dependencies do not hold any reference to the
72-
// test cluster, here the SQLRunner is only used to populate the mocked
73-
// catalog state.
74-
descriptorCatalog := sctestdeps.ReadDescriptorsFromDB(ctx, t, tdb).Catalog
75-
76-
// Set up a reference provider factory for the purpose of proper
77-
// dependency resolution.
78-
execCfg := s.ExecutorConfig().(sql.ExecutorConfig)
79-
refFactory, cleanup := sql.NewReferenceProviderFactoryForTest(
80-
ctx, "test" /* opName */, kv.NewTxn(context.Background(), s.DB(), nodeID), username.RootUserName(), &execCfg, "defaultdb",
81-
)
82-
defer cleanup()
83-
84-
fn(
85-
sctestdeps.NewTestDependencies(
86-
sctestdeps.WithDescriptors(descriptorCatalog),
87-
sctestdeps.WithSystemDatabaseDescriptor(),
88-
sctestdeps.WithNamespace(sctestdeps.ReadNamespaceFromDB(t, tdb).Catalog),
89-
sctestdeps.WithCurrentDatabase(sctestdeps.ReadCurrentDatabaseFromDB(t, tdb)),
90-
sctestdeps.WithSessionData(
91-
sctestdeps.ReadSessionDataFromDB(
92-
t,
93-
tdb,
94-
func(sd *sessiondata.SessionData, localData sessiondatapb.LocalOnlySessionData) {
95-
// For setting up a builder inside tests we will ensure that the new schema
96-
// changer will allow non-fully implemented operations.
97-
sd.NewSchemaChangerMode = sessiondatapb.UseNewSchemaChangerUnsafeAlways
98-
sd.ApplicationName = ""
99-
sd.EnableUniqueWithoutIndexConstraints = true
100-
sd.SerialNormalizationMode = localData.SerialNormalizationMode
101-
},
102-
),
103-
),
104-
sctestdeps.WithComments(sctestdeps.ReadCommentsFromDB(t, tdb)),
105-
sctestdeps.WithZoneConfigs(sctestdeps.ReadZoneConfigsFromDB(t, tdb, descriptorCatalog)),
106-
// Though we want to mock up data for this test setting, it's hard
107-
// to mimic the ID generator and optimizer (resolve all
108-
// dependencies in functions and views). So we need these pieces
109-
// to be similar as sql dependencies.
110-
sctestdeps.WithIDGenerator(s),
111-
sctestdeps.WithReferenceProviderFactory(refFactory),
112-
),
113-
)
114-
},
115-
},
116-
} {
117-
t.Run(depsType.name, func(t *testing.T) {
118-
s, sqlDB, _ := serverutils.StartServer(t, base.TestServerArgs{})
119-
defer s.Stopper().Stop(ctx)
120-
tt := s.ApplicationLayer()
121-
tdb := sqlutils.MakeSQLRunner(sqlDB)
122-
datadriven.RunTest(t, path, func(t *testing.T, d *datadriven.TestData) string {
123-
return run(ctx, t, depsType.name, d, tt, s.NodeID(), tdb, depsType.dependenciesWrapper)
124-
})
125-
})
126-
}
62+
s, sqlDB, _ := serverutils.StartServer(t, base.TestServerArgs{})
63+
defer s.Stopper().Stop(ctx)
64+
tt := s.ApplicationLayer()
65+
tdb := sqlutils.MakeSQLRunner(sqlDB)
66+
datadriven.RunTest(t, path, func(t *testing.T, d *datadriven.TestData) string {
67+
return run(ctx, t, "sql_dependencies", d, tt, s.NodeID(), tdb, dependenciesWrapper)
68+
})
69+
})
70+
}
71+
72+
func TestBuildDataDrivenWithTestDependencies(t *testing.T) {
73+
defer leaktest.AfterTest(t)()
74+
defer log.Scope(t).Close(t)
75+
defer ccl.TestingEnableEnterprise()() // allow usage of partitions and zone configs
76+
77+
ctx := context.Background()
78+
79+
skip.UnderRace(t, "expensive and can easily extend past test timeout")
80+
skip.UnderDeadlock(t, "expensive and can easily extend past test timeout")
81+
82+
dependenciesWrapper := func(t *testing.T, s serverutils.ApplicationLayerInterface, nodeID roachpb.NodeID, tdb *sqlutils.SQLRunner, fn func(scbuild.Dependencies)) {
83+
// Create test dependencies and execute the schema changer.
84+
// The schema changer test dependencies do not hold any reference to the
85+
// test cluster, here the SQLRunner is only used to populate the mocked
86+
// catalog state.
87+
descriptorCatalog := sctestdeps.ReadDescriptorsFromDB(ctx, t, tdb).Catalog
88+
89+
// Set up a reference provider factory for the purpose of proper
90+
// dependency resolution.
91+
execCfg := s.ExecutorConfig().(sql.ExecutorConfig)
92+
refFactory, cleanup := sql.NewReferenceProviderFactoryForTest(
93+
ctx, "test" /* opName */, kv.NewTxn(context.Background(), s.DB(), nodeID), username.RootUserName(), &execCfg, "defaultdb",
94+
)
95+
defer cleanup()
96+
97+
fn(
98+
sctestdeps.NewTestDependencies(
99+
sctestdeps.WithDescriptors(descriptorCatalog),
100+
sctestdeps.WithSystemDatabaseDescriptor(),
101+
sctestdeps.WithNamespace(sctestdeps.ReadNamespaceFromDB(t, tdb).Catalog),
102+
sctestdeps.WithCurrentDatabase(sctestdeps.ReadCurrentDatabaseFromDB(t, tdb)),
103+
sctestdeps.WithSessionData(
104+
sctestdeps.ReadSessionDataFromDB(
105+
t,
106+
tdb,
107+
func(sd *sessiondata.SessionData, localData sessiondatapb.LocalOnlySessionData) {
108+
// For setting up a builder inside tests we will ensure that the new schema
109+
// changer will allow non-fully implemented operations.
110+
sd.NewSchemaChangerMode = sessiondatapb.UseNewSchemaChangerUnsafeAlways
111+
sd.ApplicationName = ""
112+
sd.EnableUniqueWithoutIndexConstraints = true
113+
sd.SerialNormalizationMode = localData.SerialNormalizationMode
114+
},
115+
),
116+
),
117+
sctestdeps.WithComments(sctestdeps.ReadCommentsFromDB(t, tdb)),
118+
sctestdeps.WithZoneConfigs(sctestdeps.ReadZoneConfigsFromDB(t, tdb, descriptorCatalog)),
119+
// Though we want to mock up data for this test setting, it's hard
120+
// to mimic the ID generator and optimizer (resolve all
121+
// dependencies in functions and views). So we need these pieces
122+
// to be similar as sql dependencies.
123+
sctestdeps.WithIDGenerator(s),
124+
sctestdeps.WithReferenceProviderFactory(refFactory),
125+
),
126+
)
127+
}
128+
129+
datadriven.Walk(t, datapathutils.TestDataPath(t), func(t *testing.T, path string) {
130+
s, sqlDB, _ := serverutils.StartServer(t, base.TestServerArgs{})
131+
defer s.Stopper().Stop(ctx)
132+
tt := s.ApplicationLayer()
133+
tdb := sqlutils.MakeSQLRunner(sqlDB)
134+
datadriven.RunTest(t, path, func(t *testing.T, d *datadriven.TestData) string {
135+
return run(ctx, t, "test_dependencies", d, tt, s.NodeID(), tdb, dependenciesWrapper)
136+
})
127137
})
128138
}
129139

0 commit comments

Comments
 (0)