locktesting

package
v3.26.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 3, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TestConcurrentLocking

func TestConcurrentLocking(
	t *testing.T,
	db *sql.DB,
	newLocker func(*testing.T) lock.Locker,
	lockTimeout time.Duration,
)

TestConcurrentLocking is a reusable test helper that verifies concurrent locker behavior. It creates the specified number of lockers using the factory function and verifies that only one locker can acquire the lock at a time.

IMPORTANT: The newLocker function MUST create lockers that compete for the SAME lock resource. For table-based lockers, this means using the same lock ID. For advisory locks, the same lock ID. If each locker targets a different resource, multiple lockers will succeed (which breaks the test).

The test verifies the core locking contract:

  1. Only one locker should successfully acquire the lock when running concurrently
  2. The other lockers should fail to acquire the lock (blocked/timeout)
  3. All lockers should complete without hanging

func TestProviderLocking

func TestProviderLocking(
	t *testing.T,
	newProvider func(*testing.T) *goose.Provider,
)

TestProviderLocking is a reusable test helper that verifies locking behavior. It creates the a bunch of providers with the same locker configuration and verifies that only one provider can apply migrations at a time.

The test verifies the core locking contract:

  1. Only one provider should apply migrations when running concurrently
  2. The other providers should apply zero migrations (blocked by lock)
  3. All providers should complete without errors
  4. Final database state should be consistent

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL