Skip to content

Commit d55e3fc

Browse files
authored
Expose TestSchemaOpts.DisableReuse for test schema creation (#1195)
The `riverdbtest.TestSchema` function has had an internal `disableReuse` option for quite some time that prevents the test schema from being checked back in at the end of a test case. This is useful in cases where a schema might be modified and not suitable for pick up by a subsequent test. I was just testing some schema-related changes in Pro and found that it would be somewhat useful to be able to use this option from that package. We can also create our own test schemas from scratch over there, but `riverdbtest.TestSchema` has a number of niceties like being able to clean up test schemas even in the event of a panic and where cleanup hooks aren't run. I don't think there's any particularly harmful effect in exposing `DisableReuse` (except that it might encourage more of its use), so it's probably okay.
1 parent a43c9c6 commit d55e3fc

1 file changed

Lines changed: 14 additions & 10 deletions

File tree

riverdbtest/riverdbtest.go

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,15 @@ var (
5151
// TestSchemaOpts are options for TestSchema. Most of the time these can be left
5252
// as nil.
5353
type TestSchemaOpts struct {
54+
// DisableReuse specifies that schema will not be checked in for reuse at
55+
// the end of tests. This is desirable in certain like cases like where a
56+
// test case is making modifications to schema.
57+
//
58+
// Not being able to reuse the schema introduces overhead to tests because
59+
// it means more schemas will need to be generated to replace one not
60+
// reused, so don't set this option unless necessary.
61+
DisableReuse bool
62+
5463
// LineTargetVersions specify target versions for migration lines being
5564
// migrated. By default all lines are migrated all the way up, but this lets
5665
// tests migrate to an only partially applied version. This option is rarely
@@ -81,11 +90,6 @@ type TestSchemaOpts struct {
8190
// instead of `schema.river_job`).
8291
ProcurePool func(ctx context.Context, schema string) (any, string)
8392

84-
// disableReuse specifies that schema will not be checked in for reuse at
85-
// the end of tests. This is desirable in certain like cases like where a
86-
// test case is making modifications to schema.
87-
disableReuse bool
88-
8993
// skipPackageNameCheck skips the check that package name doesn't resolve to
9094
// `riverdbtest`. Normally we want this to make sure that we're skipping
9195
// the right number of frames back to the caller package, but it needs to be
@@ -279,7 +283,7 @@ func TestSchema[TTx any](ctx context.Context, tb testutil.TestingTB, driver rive
279283
}
280284

281285
if withCleanup, ok := tb.(testingTBWithCleanup); ok {
282-
if !opts.disableReuse {
286+
if !opts.DisableReuse {
283287
withCleanup.Cleanup(func() {
284288
idleSchemasMu.Lock()
285289
defer idleSchemasMu.Unlock()
@@ -638,15 +642,15 @@ func testTxSchemaForDatabaseAndMigrationLines[TTx any](ctx context.Context, tb t
638642
}
639643

640644
schema = TestSchema(ctx, tb, driver, &TestSchemaOpts{
641-
Lines: lines,
642-
ProcurePool: opts.ProcurePool,
643-
644645
// If test transactions are being shared (opts.DisableSharing = false)
645646
// then reserve the shared schemas exclusively for TestTx. Otherwise,
646647
// allow them to be put back in the pool for use by other test
647648
// transactions with opts.DisableSharing = true or other TestSchema
648649
// invocations.
649-
disableReuse: !opts.DisableSchemaSharing,
650+
DisableReuse: !opts.DisableSchemaSharing,
651+
652+
Lines: lines,
653+
ProcurePool: opts.ProcurePool,
650654

651655
skipExtraFrames: skipExtraFrames,
652656
skipPackageNameCheck: opts.skipPackageNameCheck,

0 commit comments

Comments
 (0)