Documentation
¶
Overview ¶
Package testutil holds helpers shared by tests only: polling assertions, in-memory fakes of domain ports and Postgres test containers. It is never imported by non-test code.
testutil.Eventually(t, func() bool { return done.Load() }, time.Second)
Index ¶
- Variables
- func Eventually(tb testing.TB, cond func() bool, timeout time.Duration, msgAndArgs ...any)
- type FakeStore
- func (s *FakeStore) AcquireLease(_ context.Context, _, id string, now time.Time, ttl time.Duration) (bool, error)
- func (s *FakeStore) CancelRequested(_ context.Context, ids []int64) ([]int64, error)
- func (s *FakeStore) Complete(_ context.Context, clientID string, cs []job.Completion) ([]int64, error)
- func (s *FakeStore) DeleteFinalized(_ context.Context, state job.State, cutoff time.Time, limit int) (int, error)
- func (s *FakeStore) EnqueueTick(_ context.Context, name string, tick time.Time, p job.InsertParams) (bool, error)
- func (s *FakeStore) FailNext(n int)
- func (s *FakeStore) Fetch(_ context.Context, p job.FetchParams) ([]*job.Row, error)
- func (s *FakeStore) Heartbeat(_ context.Context, clientID string, now time.Time, refs []job.Ref) (int, error)
- func (s *FakeStore) Insert(p job.InsertParams) int64
- func (s *FakeStore) Job(id int64) (job.Row, bool)
- func (s *FakeStore) Jobs() []job.Row
- func (s *FakeStore) KeyStats(_ context.Context, queue string, limit int, _ bool) ([]job.KeyStat, error)
- func (s *FakeStore) LastTicks(context.Context) (map[string]time.Time, error)
- func (s *FakeStore) LeaseHolder() (string, time.Time)
- func (s *FakeStore) MarkPeriodicStart(_ context.Context, name string, now time.Time) error
- func (s *FakeStore) PromoteDue(_ context.Context, now time.Time, limit int) (int, error)
- func (s *FakeStore) PruneTicks(_ context.Context, cutoff time.Time) (int, error)
- func (s *FakeStore) QueueDepths(context.Context) ([]job.QueueDepth, error)
- func (s *FakeStore) QueueHeartbeat(_ context.Context, queue string, _ time.Time) (bool, error)
- func (s *FakeStore) Reindex(context.Context) (bool, error)
- func (s *FakeStore) ReleaseLease(_ context.Context, _, id string) error
- func (s *FakeStore) RenewLease(_ context.Context, _, id string, now time.Time, ttl time.Duration) (bool, error)
- func (s *FakeStore) Rescue(_ context.Context, cutoff time.Time, cs []job.Completion) (int, error)
- func (s *FakeStore) RunningByKey(queue string) map[string]int
- func (s *FakeStore) SetPaused(queue string, paused bool)
- func (s *FakeStore) StuckJobs(_ context.Context, cutoff time.Time, limit int) ([]*job.Row, error)
- func (s *FakeStore) Ticks(name string) []time.Time
- func (s *FakeStore) Update(id int64, fn func(*job.Row))
Constants ¶
This section is empty.
Variables ¶
var ErrInjected = errors.New("fakestore: injected failure")
ErrInjected is returned by FakeStore when a failure is injected.
Functions ¶
Types ¶
type FakeStore ¶
type FakeStore struct {
FetchHook func(rows []*job.Row) // called with fetched rows while the lock is held
// contains filtered or unexported fields
}
FakeStore is an in-memory implementation of the job store ports with the same semantics as the Postgres adapter: fetch order, per-key limits, the completion guard, leases and periodic ticks. One mutex makes every operation atomic, which models row locks and advisory locks.
func (*FakeStore) AcquireLease ¶
func (s *FakeStore) AcquireLease(_ context.Context, _, id string, now time.Time, ttl time.Duration) (bool, error)
AcquireLease implements job.LeaseStore.
func (*FakeStore) CancelRequested ¶
CancelRequested implements job.CancelPoller.
func (*FakeStore) Complete ¶
func (s *FakeStore) Complete(_ context.Context, clientID string, cs []job.Completion) ([]int64, error)
Complete implements job.CompletionWriter.
func (*FakeStore) DeleteFinalized ¶
func (s *FakeStore) DeleteFinalized(_ context.Context, state job.State, cutoff time.Time, limit int) (int, error)
DeleteFinalized implements job.MaintenanceStore.
func (*FakeStore) EnqueueTick ¶
func (s *FakeStore) EnqueueTick(_ context.Context, name string, tick time.Time, p job.InsertParams) (bool, error)
EnqueueTick implements job.MaintenanceStore.
func (*FakeStore) Heartbeat ¶
func (s *FakeStore) Heartbeat(_ context.Context, clientID string, now time.Time, refs []job.Ref) (int, error)
Heartbeat implements job.HeartbeatWriter.
func (*FakeStore) Insert ¶
func (s *FakeStore) Insert(p job.InsertParams) int64
Insert adds a job and returns its id.
func (*FakeStore) KeyStats ¶
func (s *FakeStore) KeyStats(_ context.Context, queue string, limit int, _ bool) ([]job.KeyStat, error)
KeyStats implements job.Fetcher.
func (*FakeStore) LeaseHolder ¶
LeaseHolder returns the current lease holder id and expiry.
func (*FakeStore) MarkPeriodicStart ¶
MarkPeriodicStart implements job.MaintenanceStore.
func (*FakeStore) PromoteDue ¶
PromoteDue implements job.MaintenanceStore.
func (*FakeStore) PruneTicks ¶
PruneTicks implements job.MaintenanceStore.
func (*FakeStore) QueueDepths ¶
QueueDepths implements job.MaintenanceStore.
func (*FakeStore) QueueHeartbeat ¶
QueueHeartbeat implements job.Fetcher.
func (*FakeStore) ReleaseLease ¶
ReleaseLease implements job.LeaseStore.
func (*FakeStore) RenewLease ¶
func (s *FakeStore) RenewLease(_ context.Context, _, id string, now time.Time, ttl time.Duration) (bool, error)
RenewLease implements job.LeaseStore.
func (*FakeStore) RunningByKey ¶
RunningByKey counts running jobs per (queue, key).
Directories
¶
| Path | Synopsis |
|---|---|
|
Package pgtest provides Postgres for integration tests: a Testcontainers server per test package (or FOREMAN_TEST_DATABASE_URL) and a freshly migrated schema per test.
|
Package pgtest provides Postgres for integration tests: a Testcontainers server per test package (or FOREMAN_TEST_DATABASE_URL) and a freshly migrated schema per test. |