|
| 1 | +//go:build test_db_postgres && !test_db_sqlite |
| 2 | + |
| 3 | +package paymentsdb |
| 4 | + |
| 5 | +import ( |
| 6 | + "database/sql" |
| 7 | + "testing" |
| 8 | + |
| 9 | + "github.com/lightningnetwork/lnd/sqldb" |
| 10 | +) |
| 11 | + |
| 12 | +// postgresFetchInFlightBenchBackend creates Postgres-backed benchmark stores. |
| 13 | +type postgresFetchInFlightBenchBackend struct { |
| 14 | + fixture *sqldb.TestPgFixture |
| 15 | +} |
| 16 | + |
| 17 | +// newFetchInFlightBenchBackend creates the benchmark backend selected by the |
| 18 | +// active build tags. |
| 19 | +func newFetchInFlightBenchBackend(b *testing.B) fetchInFlightBenchBackend { |
| 20 | + b.Helper() |
| 21 | + |
| 22 | + fixture := sqldb.NewTestPgFixture( |
| 23 | + b, sqldb.DefaultPostgresFixtureLifetime, |
| 24 | + ) |
| 25 | + b.Cleanup(func() { |
| 26 | + fixture.TearDown(b) |
| 27 | + }) |
| 28 | + |
| 29 | + return postgresFetchInFlightBenchBackend{fixture: fixture} |
| 30 | +} |
| 31 | + |
| 32 | +// newStore creates a migrated Postgres SQLStore and seeds it with one benchmark |
| 33 | +// scenario. |
| 34 | +func (backend postgresFetchInFlightBenchBackend) newStore(b *testing.B, |
| 35 | + scenario fetchInFlightBenchScenario, |
| 36 | + totalPayments int) (*SQLStore, fetchInFlightBenchSeedStats) { |
| 37 | + |
| 38 | + b.Helper() |
| 39 | + |
| 40 | + pgDB := sqldb.NewTestPostgresDB(b, backend.fixture) |
| 41 | + baseDB := pgDB.BaseDB |
| 42 | + |
| 43 | + withTx := func(tx *sql.Tx) SQLQueries { |
| 44 | + return baseDB.WithTx(tx) |
| 45 | + } |
| 46 | + queries := sqldb.NewTransactionExecutor(baseDB, withTx) |
| 47 | + |
| 48 | + store, err := NewSQLStore(&SQLStoreConfig{ |
| 49 | + QueryCfg: sqldb.DefaultPostgresConfig(), |
| 50 | + }, queries) |
| 51 | + if err != nil { |
| 52 | + b.Fatalf("new SQL store: %v", err) |
| 53 | + } |
| 54 | + |
| 55 | + stats := seedFetchInFlightBenchDB( |
| 56 | + b, baseDB.DB, withTx, scenario, totalPayments, |
| 57 | + ) |
| 58 | + |
| 59 | + return store, stats |
| 60 | +} |
0 commit comments