(ctx context.Context, tb testing.TB, driver riverdriver.Driver[TTx], opts *TestTxOpts)
| 596 | ) |
| 597 | |
| 598 | func testTxSchemaForDatabaseAndMigrationLines[TTx any](ctx context.Context, tb testing.TB, driver riverdriver.Driver[TTx], opts *TestTxOpts) string { |
| 599 | tb.Helper() |
| 600 | |
| 601 | if opts == nil { |
| 602 | opts = &TestTxOpts{} |
| 603 | } |
| 604 | |
| 605 | lines := driver.GetMigrationDefaultLines() |
| 606 | if opts.lines != nil { |
| 607 | lines = opts.lines |
| 608 | } |
| 609 | |
| 610 | var databaseAndLinesKey string |
| 611 | var schema string |
| 612 | |
| 613 | if !opts.DisableSchemaSharing { |
| 614 | // Transaction schemas must be managed by database and which migration lines |
| 615 | // were run within them, which is determined by the included driver. i.e. A |
| 616 | // schema with no migrations obviously cannot be reused for a test expecting |
| 617 | // the `main` migration line. An SQLite schema can't be reused for Postgres. |
| 618 | // |
| 619 | // linesKey acts as key specific to this migrations set for testTxSchemas. |
| 620 | slices.Sort(lines) |
| 621 | databaseAndLinesKey = strings.Join(append([]string{driver.DatabaseName()}, lines...), ",") |
| 622 | |
| 623 | testTxSchemasMu.RLock() |
| 624 | schema := testTxSchemas[databaseAndLinesKey] |
| 625 | testTxSchemasMu.RUnlock() |
| 626 | |
| 627 | if schema != "" { |
| 628 | return schema |
| 629 | } |
| 630 | |
| 631 | testTxSchemasMu.Lock() |
| 632 | defer testTxSchemasMu.Unlock() |
| 633 | |
| 634 | // Check for a schema once more in case there was a race to acquire the |
| 635 | // mutex lock and another TestTx invocation did it first. |
| 636 | if schema = testTxSchemas[databaseAndLinesKey]; schema != "" { |
| 637 | return schema |
| 638 | } |
| 639 | } |
| 640 | |
| 641 | // If called from a transaction helper like `TestTxPgx`, skip one more frame |
| 642 | // for purposes of schema naming. |
| 643 | skipExtraFrames := 2 |
| 644 | if opts.IsTestTxHelper { |
| 645 | skipExtraFrames += 2 |
| 646 | } |
| 647 | |
| 648 | schema = TestSchema(ctx, tb, driver, &TestSchemaOpts{ |
| 649 | // If test transactions are being shared (opts.DisableSharing = false) |
| 650 | // then reserve the shared schemas exclusively for TestTx. Otherwise, |
| 651 | // allow them to be put back in the pool for use by other test |
| 652 | // transactions with opts.DisableSharing = true or other TestSchema |
| 653 | // invocations. |
| 654 | DisableReuse: !opts.DisableSchemaSharing, |
| 655 |
searching dependent graphs…