MCPcopy
hub / github.com/riverqueue/river / DBPool

Function DBPool

rivershared/riversharedtest/riversharedtest.go:51–81  ·  view source on GitHub ↗

DBPool gets a lazily initialized database pool for `TEST_DATABASE_URL` or `river_test` if the former isn't specified.

(ctx context.Context, tb testing.TB)

Source from the content-addressed store, hash-verified

49// DBPool gets a lazily initialized database pool for `TEST_DATABASE_URL` or
50// `river_test` if the former isn't specified.
51func DBPool(ctx context.Context, tb testing.TB) *pgxpool.Pool {
52 tb.Helper()
53
54 dbPoolOnce.Do(func() {
55 config, err := pgxpool.ParseConfig(TestDatabaseURL())
56 require.NoError(tb, err)
57
58 config.AfterConnect = func(ctx context.Context, conn *pgx.Conn) error {
59 // Empty the search path so that tests using riverdbtest are
60 // forced to pass a schema to clients and any other database
61 // operations they invoke. Calls do not accidentally fall back to a
62 // default schema, which would potentially hide bugs where we
63 // weren't properly referencing a schema explicitly.
64 _, err := conn.Exec(ctx, "SET search_path TO ''")
65
66 // This should not be a `require` because the callback may run long
67 // after the original test has completed.
68 if err != nil && !errors.Is(err, context.Canceled) {
69 panic(err)
70 }
71
72 return nil
73 }
74
75 dbPool, err = pgxpool.NewWithConfig(ctx, config)
76 require.NoError(tb, err)
77 })
78 require.NotNil(tb, dbPool) // die in case initial connect from another test failed
79
80 return dbPool
81}
82
83// DBPoolClone returns a disposable clone of DBPool. Share resources by using
84// DBPool when possible, but this is useless for areas like stress tests where

Callers 15

TestClientDriverPluginFunction · 0.92
TestClientPilotPluginFunction · 0.92
TestWorkFuncFunction · 0.92
Test_RecordedOutputFunction · 0.92
runNewTestClientFunction · 0.92
Test_Client_Stop_CommonFunction · 0.92
Test_Client_JobDeleteFunction · 0.92
Test_Client_JobDeleteTxFunction · 0.92

Calls 4

TestDatabaseURLFunction · 0.85
HelperMethod · 0.65
ExecMethod · 0.65
IsMethod · 0.45

Tested by 15

TestClientDriverPluginFunction · 0.74
TestClientPilotPluginFunction · 0.74
TestWorkFuncFunction · 0.74
Test_RecordedOutputFunction · 0.74
runNewTestClientFunction · 0.74
Test_Client_Stop_CommonFunction · 0.74
Test_Client_JobDeleteFunction · 0.74
Test_Client_JobDeleteTxFunction · 0.74

Used in the wild real call sites across dependent graphs

searching dependent graphs…