@@ -114,40 +114,23 @@ func backupRestoreRoundTrip(
114
114
m := c .NewMonitor (ctx , c .CRDBNodes ())
115
115
116
116
m .Go (func (ctx context.Context ) error {
117
- connectFunc := func (node int ) (* gosql.DB , error ) {
118
- conn , err := c .ConnE (ctx , t .L (), node )
119
- if err != nil {
120
- return nil , fmt .Errorf ("failed to connect to node %d: %w" , node , err )
121
- }
122
-
123
- return conn , err
124
- }
125
- // TODO (msbutler): enable compaction for online restore test once inc layer limit is increased.
126
- testUtils , err := newCommonTestUtils (ctx , t , c , connectFunc , c .CRDBNodes (), withMock (sp .mock ), withOnlineRestore (sp .onlineRestore ), withCompaction (! sp .onlineRestore ))
117
+ testUtils , err := setupBackupRestoreTestUtils (
118
+ ctx , t , c , m , testRNG ,
119
+ withMock (sp .mock ), withOnlineRestore (sp .onlineRestore ), withCompaction (! sp .onlineRestore ),
120
+ )
127
121
if err != nil {
128
122
return err
129
123
}
130
124
defer testUtils .CloseConnections ()
131
125
132
126
dbs := []string {"bank" , "tpcc" , schemaChangeDB }
133
- runBackgroundWorkload , err := startBackgroundWorkloads (ctx , t .L (), c , m , testRNG , c .CRDBNodes (), c .WorkloadNode (), testUtils , dbs )
134
- if err != nil {
135
- return err
136
- }
137
- tables , err := testUtils .loadTablesForDBs (ctx , t .L (), testRNG , dbs ... )
138
- if err != nil {
139
- return err
140
- }
141
- d , err := newBackupRestoreTestDriver (ctx , t , c , testUtils , c .CRDBNodes (), dbs , tables )
127
+ d , runBackgroundWorkload , _ , err := createDriversForBackupRestore (
128
+ ctx , t , c , m , testRNG , testUtils , dbs ,
129
+ )
142
130
if err != nil {
143
131
return err
144
132
}
145
- if err := testUtils .setShortJobIntervals (ctx , testRNG ); err != nil {
146
- return err
147
- }
148
- if err := testUtils .setClusterSettings (ctx , t .L (), c , testRNG ); err != nil {
149
- return err
150
- }
133
+
151
134
if sp .metamorphicRangeSize {
152
135
if err := testUtils .setMaxRangeSizeAndDependentSettings (ctx , t , testRNG , dbs ); err != nil {
153
136
return err
@@ -199,7 +182,7 @@ func backupRestoreRoundTrip(
199
182
200
183
t .L ().Printf ("verifying backup %d" , i + 1 )
201
184
// Verify content in backups.
202
- err = collection .verifyBackupCollection (ctx , t .L (), testRNG , d , true /* checkFiles */ , true /* internalSystemJobs */ )
185
+ err = d .verifyBackupCollection (ctx , t .L (), testRNG , collection , true /* checkFiles */ , true /* internalSystemJobs */ )
203
186
if err != nil {
204
187
return err
205
188
}
@@ -220,8 +203,8 @@ func backupRestoreRoundTrip(
220
203
m .Wait ()
221
204
}
222
205
223
- // startBackgroundWorkloads starts a TPCC, bank, and a system table workload in
224
- // the background.
206
+ // startBackgroundWorkloads returns a function that starts a TPCC, bank, and a
207
+ // system table workload in the background.
225
208
func startBackgroundWorkloads (
226
209
ctx context.Context ,
227
210
l * logger.Logger ,
@@ -361,7 +344,6 @@ func (u *CommonTestUtils) CloseConnections() {
361
344
}
362
345
363
346
func workloadWithCancel (m cluster.Monitor , fn func (ctx context.Context ) error ) func () {
364
-
365
347
cancelWorkload := m .GoWithCancel (func (ctx context.Context ) error {
366
348
err := fn (ctx )
367
349
if ctx .Err () != nil {
@@ -372,3 +354,65 @@ func workloadWithCancel(m cluster.Monitor, fn func(ctx context.Context) error) f
372
354
})
373
355
return cancelWorkload
374
356
}
357
+
358
+ // setupBackupRestoreTestUtils sets up a CommonTestUtils instance for backup and
359
+ // restore tests and initializes some useful settings.
360
+ func setupBackupRestoreTestUtils (
361
+ ctx context.Context ,
362
+ t test.Test ,
363
+ c cluster.Cluster ,
364
+ m cluster.Monitor ,
365
+ rng * rand.Rand ,
366
+ testOpts ... commonTestOption ,
367
+ ) (* CommonTestUtils , error ) {
368
+ connectFunc := func (node int ) (* gosql.DB , error ) {
369
+ conn , err := c .ConnE (ctx , t .L (), node )
370
+ if err != nil {
371
+ return nil , fmt .Errorf ("failed to connect to node %d: %w" , node , err )
372
+ }
373
+
374
+ return conn , err
375
+ }
376
+ // TODO (msbutler): enable compaction for online restore test once inc layer limit is increased.
377
+ testUtils , err := newCommonTestUtils (ctx , t , c , connectFunc , c .CRDBNodes (), testOpts ... )
378
+ if err != nil {
379
+ return nil , err
380
+ }
381
+ if err := testUtils .setShortJobIntervals (ctx , rng ); err != nil {
382
+ return nil , err
383
+ }
384
+ if err := testUtils .setClusterSettings (ctx , t .L (), c , rng ); err != nil {
385
+ return nil , err
386
+ }
387
+ return testUtils , err
388
+ }
389
+
390
+ // createDriversForBackupRestore creates a BackupRestoreTestDriver for backup
391
+ // and restore tests, a handler to trigger background workloads, and the tables
392
+ // that are used in the test. The tables are mapped to the databases that were
393
+ // passed in.
394
+ func createDriversForBackupRestore (
395
+ ctx context.Context ,
396
+ t test.Test ,
397
+ c cluster.Cluster ,
398
+ m cluster.Monitor ,
399
+ rng * rand.Rand ,
400
+ testUtils * CommonTestUtils ,
401
+ dbs []string ,
402
+ ) (* BackupRestoreTestDriver , func () (func (), error ), [][]string , error ) {
403
+ runBackgroundWorkload , err := startBackgroundWorkloads (
404
+ ctx , t .L (), c , m , rng , c .CRDBNodes (), c .WorkloadNode (), testUtils , dbs ,
405
+ )
406
+ if err != nil {
407
+ return nil , nil , nil , err
408
+ }
409
+ tables , err := testUtils .loadTablesForDBs (ctx , t .L (), rng , dbs ... )
410
+ if err != nil {
411
+ return nil , nil , nil , err
412
+ }
413
+ d , err := newBackupRestoreTestDriver (ctx , t , c , testUtils , c .CRDBNodes (), dbs , tables )
414
+ if err != nil {
415
+ return nil , nil , nil , err
416
+ }
417
+ return d , runBackgroundWorkload , tables , nil
418
+ }
0 commit comments