Documentation ¶
Overview ¶
Package riverinternaltest contains shared testing utilities for tests throughout the rest of the project.
Index ¶
- Constants
- func DatabaseConfig(databaseName string) *pgxpool.Config
- func DatabaseURL(databaseName string) string
- func DiscardContinuously[T any](drainChan <-chan T) func()
- func DrainContinuously[T any](drainChan <-chan T) func() []T
- func TestDB(ctx context.Context, tb testing.TB) *pgxpool.Pool
- func TestTx(ctx context.Context, tb testing.TB) pgx.Tx
- func TruncateRiverTables(ctx context.Context, pool *pgxpool.Pool) error
- func WrapTestMain(m *testing.M)
Constants ¶
const SchedulerShortInterval = 500 * time.Millisecond
SchedulerShortInterval is an artificially short interval for the scheduler that's used in the tests of various components to make sure that errored jobs always end up in a `retryable` state rather than `available`. Normally, the job executor sets `available` if the retry delay is smaller than the scheduler's interval. To simplify things so errors are always `retryable`, this time is picked to be smaller than any retry delay that the default retry policy will ever produce. It's shared so we can document/explain it all in one place.
Variables ¶
This section is empty.
Functions ¶
func DatabaseConfig ¶
func DatabaseURL ¶ added in v0.0.13
DatabaseURL gets a test database URL from TEST_DATABASE_URL or falls back on a default pointing to `river_test`. If databaseName is set, it replaces the database in the URL, although the host and other parameters are preserved.
Most of the time DatabaseConfig should be used instead of this function, but it may be useful in non-pgx situations like for examples showing the use of `database/sql`.
func DiscardContinuously ¶
func DiscardContinuously[T any](drainChan <-chan T) func()
DiscardContinuously drains continuously out of the given channel and discards anything that comes out of it. Returns a stop function that should be invoked to stop draining. Stop must be invoked before tests finish to stop an internal goroutine.
func DrainContinuously ¶
func DrainContinuously[T any](drainChan <-chan T) func() []T
DrainContinuously drains continuously out of the given channel and accumulates items that are received from it. Returns a get function that can be called to retrieve the current set of received items, and which will also cause the function to shut down and stop draining. This function must be invoked before tests finish to stop an internal goroutine. It's safe to call it multiple times.
func TestDB ¶
TestDB acquires a dedicated test database for the duration of the test. If an error occurs, the test fails. The test database will be automatically returned to the pool at the end of the test and the pgxpool will be closed.
func TestTx ¶
TestTx starts a test transaction that's rolled back automatically as the test case is cleaning itself up. This can be used as a lighter weight alternative to `testdb.Manager` in components where it's not necessary to have many connections open simultaneously.
func TruncateRiverTables ¶
TruncateRiverTables truncates River tables in the target database. This is for test cleanup and should obviously only be used in tests.
func WrapTestMain ¶
WrapTestMain performs some common setup and teardown that should be shared amongst all packages. e.g. Configures a manager for test databases on setup, and checks for no goroutine leaks on teardown.
Types ¶
This section is empty.