forked from mtusi2026/mtusi2026lab5
fix: enforce pipeline lifecycle limits
This commit is contained in:
@@ -70,6 +70,18 @@ func TestDispatcherRejectsStaleLeaseAfterPublish(t *testing.T) {
|
||||
require.Zero(t, published)
|
||||
}
|
||||
|
||||
func TestDispatcherCleansPublishedEventsBeforeRetentionCutoff(t *testing.T) {
|
||||
store := &storeStub{deleted: 2}
|
||||
dispatcher := newTestDispatcher(t, store, &publisherStub{})
|
||||
dispatcher.now = func() time.Time { return time.Date(2026, 10, 22, 12, 0, 0, 0, time.UTC) }
|
||||
|
||||
deleted, err := dispatcher.CleanupPublished(context.Background())
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, 2, deleted)
|
||||
require.Equal(t, dispatcher.now().Add(-24*time.Hour), store.publishedBefore)
|
||||
require.Equal(t, 100, store.cleanupLimit)
|
||||
}
|
||||
|
||||
func TestDispatcherStopsAfterCancellation(t *testing.T) {
|
||||
store := &storeStub{}
|
||||
publisher := &publisherStub{}
|
||||
@@ -96,6 +108,9 @@ func newTestDispatcher(t *testing.T, store Store, publisher Publisher) *Dispatch
|
||||
PollInterval: time.Millisecond,
|
||||
RecoveryInterval: time.Second,
|
||||
RetryDelay: time.Second,
|
||||
Retention: 24 * time.Hour,
|
||||
CleanupInterval: time.Hour,
|
||||
CleanupBatchSize: 100,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
return dispatcher
|
||||
@@ -114,14 +129,17 @@ func testPayload() json.RawMessage {
|
||||
}
|
||||
|
||||
type storeStub struct {
|
||||
mu sync.Mutex
|
||||
events []model.OutboxEvent
|
||||
markErr error
|
||||
markLost bool
|
||||
marked []string
|
||||
released string
|
||||
nextAttemptAt time.Time
|
||||
recoveredCalls int
|
||||
mu sync.Mutex
|
||||
events []model.OutboxEvent
|
||||
markErr error
|
||||
markLost bool
|
||||
marked []string
|
||||
released string
|
||||
nextAttemptAt time.Time
|
||||
recoveredCalls int
|
||||
deleted int
|
||||
publishedBefore time.Time
|
||||
cleanupLimit int
|
||||
}
|
||||
|
||||
func (s *storeStub) ClaimOutboxEvents(context.Context, int, time.Duration) ([]model.OutboxEvent, error) {
|
||||
@@ -164,6 +182,14 @@ func (s *storeStub) RecoverExpiredOutboxEvents(context.Context, time.Time) (int,
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
func (s *storeStub) DeletePublishedOutboxEvents(_ context.Context, before time.Time, limit int) (int, error) {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
s.publishedBefore = before
|
||||
s.cleanupLimit = limit
|
||||
return s.deleted, nil
|
||||
}
|
||||
|
||||
type publisherStub struct {
|
||||
mu sync.Mutex
|
||||
messageID string
|
||||
|
||||
Reference in New Issue
Block a user