Skip to content

Commit 9f899e1

Browse files
committed
roachtest: use functional args in newCommonTestUtils
Epic: none Release note: none
1 parent d1bfdaa commit 9f899e1

File tree

3 files changed

+27
-13
lines changed

3 files changed

+27
-13
lines changed

pkg/cmd/roachtest/tests/backup_restore_roundtrip.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ func backupRestoreRoundTrip(
122122

123123
return conn, err
124124
}
125-
testUtils, err := newCommonTestUtils(ctx, t, c, connectFunc, c.CRDBNodes(), sp.mock, sp.onlineRestore)
125+
testUtils, err := newCommonTestUtils(ctx, t, c, connectFunc, c.CRDBNodes(), withMock(sp.mock), withOnlineRestore(sp.onlineRestore))
126126
if err != nil {
127127
return err
128128
}

pkg/cmd/roachtest/tests/mixed_version_backup.go

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2844,17 +2844,28 @@ type CommonTestUtils struct {
28442844
}
28452845
}
28462846

2847-
// newCommonTestUtils creates a connection to each node (given that the nodes list is not empty)
2848-
// and puts these connections in a cache for reuse. The caller should remember to close all connections
2849-
// once done with them to prevent any goroutine leaks (CloseConnections).
2847+
type commonTestOption func(*CommonTestUtils)
2848+
2849+
func withMock(mock bool) commonTestOption {
2850+
return func(c *CommonTestUtils) {
2851+
c.mock = mock
2852+
}
2853+
}
2854+
2855+
func withOnlineRestore(or bool) commonTestOption {
2856+
return func(c *CommonTestUtils) {
2857+
c.onlineRestore = or
2858+
}
2859+
}
2860+
2861+
// Change the function signature
28502862
func newCommonTestUtils(
28512863
ctx context.Context,
28522864
t test.Test,
28532865
c cluster.Cluster,
28542866
connectFunc func(int) (*gosql.DB, error),
28552867
nodes option.NodeListOption,
2856-
mock bool,
2857-
onlineRestore bool,
2868+
opts ...commonTestOption,
28582869
) (*CommonTestUtils, error) {
28592870
cc := make([]*gosql.DB, len(nodes))
28602871
for _, node := range nodes {
@@ -2870,13 +2881,16 @@ func newCommonTestUtils(
28702881
}
28712882

28722883
u := &CommonTestUtils{
2873-
t: t,
2874-
cluster: c,
2875-
roachNodes: nodes,
2876-
mock: mock,
2877-
onlineRestore: onlineRestore,
2884+
t: t,
2885+
cluster: c,
2886+
roachNodes: nodes,
28782887
}
28792888
u.connCache.cache = cc
2889+
2890+
// Apply all options
2891+
for _, opt := range opts {
2892+
opt(u)
2893+
}
28802894
return u, nil
28812895
}
28822896

@@ -2887,7 +2901,7 @@ func (mvb *mixedVersionBackup) CommonTestUtils(
28872901
mvb.utilsOnce.Do(func() {
28882902
connectFunc := func(node int) (*gosql.DB, error) { return h.Connect(node), nil }
28892903
mvb.commonTestUtils, err = newCommonTestUtils(
2890-
ctx, mvb.t, mvb.cluster, connectFunc, mvb.roachNodes, false, false,
2904+
ctx, mvb.t, mvb.cluster, connectFunc, mvb.roachNodes,
28912905
)
28922906
})
28932907
return mvb.commonTestUtils, err

pkg/cmd/roachtest/tests/mixed_version_job_compatibility_in_declarative_schema_changer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func executeSupportedDDLs(
8686
// here because these connnections are managed by the mixedversion
8787
// framework, which already closes them at the end of the test.
8888
testUtils, err := newCommonTestUtils(
89-
ctx, t, c, connectFunc, helper.DefaultService().Descriptor.Nodes, false, false,
89+
ctx, t, c, connectFunc, helper.DefaultService().Descriptor.Nodes,
9090
)
9191
if err != nil {
9292
return err

0 commit comments

Comments
 (0)