Skip to content

Commit 1fc5966

Browse files
authored
test(faucet): a run past the lease sends no gap or delivery again (#35)
* test(faucet): lapse every lease before the gap exactly-once checks A gap that a run counted as sent but never finished goes out again once its 30 s DeliveryLease lapses. The two gap tests never moved the clock past a lease, so no run could send a gap twice, and requireEachGapSentOnce could not see it. Both tests now advance past DeliveryLease and run DeliverDue once more before the checks, so the helper's claim that no run sends a gap again is checked. --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-sonnet-5-5` • Thinking: `xhigh`_ * test(faucet): make lapseEveryLease check its own run The helper ran deliverDue once more past DeliveryLease and dropped the result. That run could send a gap that an earlier run counted as sent and never finished, and the receiver then saw exactly one envelope, so a mutant that counted the first claim of each slow gap without a request or FinishGap passed both tests. After a correct run nothing is left to send. Require the lapse run to count no gap. --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-sonnet-5-5` • Thinking: `xhigh`_ * test(faucet): check the receivers before the lease-lapse run too The lapse run could send the one request that hid a gap an earlier run counted and never sent. Checking what the receivers saw before it keeps main's check intact, so the lapse run can only add a failure. --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `high`_ * test(faucet): drop the lease-lapse run from the fairness tests The extra DeliverDue run let the tests repair defects that main's checks already catch. Return fairness_test.go to main's version. * test(faucet): a run past the lease sends no gap or delivery again A gap or a delivery that a run counts as sent but never finishes keeps its lease, and the first run after DeliveryLease sends it again. Queue gaps and deliveries, run once, check the receivers and the books, then run past the lease and require that nothing is claimed or sent. * test(faucet): word the lease-lapse assertions without colons
1 parent 475148a commit 1fc5966

1 file changed

Lines changed: 57 additions & 0 deletions

File tree

‎faucet/deliver_test.go‎

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,63 @@ func TestDeliverDueTakesBackADeliveryWhenALeaseRunsOut(t *testing.T) {
492492
})
493493
}
494494

495+
// A run counts a gap or a delivery when its request is done, and must also
496+
// finish it. A send that is counted but not finished keeps its lease, and the
497+
// first run after the lease sends it again. The counts of the first run and the
498+
// receivers after it cannot show that, so this test runs once more past the
499+
// lease, and nothing may go out. There are more gaps than workers, so that a
500+
// worker which finishes only its first gap leaves some unfinished. One gap
501+
// endpoint answers slowly, so that a request that takes long is finished too.
502+
// The origin has no limit, so that no worker passes a gap over and one call
503+
// sends everything.
504+
func TestDeliverDueARunPastTheLeaseSendsNothingAgain(t *testing.T) {
505+
t.Parallel()
506+
507+
const workers = 8
508+
const subscriptions = 4 * workers
509+
d := newDeliverHarness(t, func(deps *faucet.Deps) { deps.Webhook.MaxWorkersPerOrigin = -1 })
510+
paths := make([]string, subscriptions)
511+
for i := range subscriptions {
512+
paths[i] = fmt.Sprintf("/sub%02d", i)
513+
d.subscribeEndpoint(d.endpoint(paths[i]))
514+
}
515+
d.rcv.answerEnvelope(paths[0], "gap", func() int {
516+
time.Sleep(200 * time.Millisecond)
517+
return http.StatusOK
518+
})
519+
d.advance(time.Second)
520+
d.newRunEvent()
521+
d.advance(5 * time.Minute)
522+
d.newRunEvent()
523+
purged, err := d.store.Purge(d.ctx, d.clock.Now().Add(-time.Minute))
524+
require.NoError(t, err)
525+
require.EqualValues(t, 1, purged.Deleted)
526+
527+
requireGapAndEventSentOnce := func() {
528+
t.Helper()
529+
requireEachGapSentOnce(t, d.rcv, paths...)
530+
for _, path := range paths {
531+
require.Len(t, d.rcv.requests(path), 2, "the subscription at %s got its gap envelope and its event once each", path)
532+
}
533+
}
534+
535+
first := d.deliverDue()
536+
require.False(t, first.Incomplete, "the first run did all the due work")
537+
require.Equal(t, subscriptions, first.GapsSent)
538+
require.Zero(t, first.GapsFailed)
539+
require.Equal(t, subscriptions, first.Delivered)
540+
requireGapAndEventSentOnce()
541+
d.requireEveryDeliveryAccountedFor()
542+
543+
d.advance(faucet.DeliveryLease + time.Second)
544+
again := d.deliverDue()
545+
require.Zero(t, again.Claimed, "a run past the lease claims nothing, because the first run finished every delivery")
546+
require.Zero(t, again.Sent, "and sends no event again")
547+
require.Zero(t, again.GapsSent+again.GapsFailed, "and sends no gap again, because the first run finished every gap")
548+
require.Zero(t, again.Delivered+again.Retried+again.GaveUpTotal()+again.Superseded, "and ends no delivery")
549+
requireGapAndEventSentOnce()
550+
}
551+
495552
func TestDeliverDueEndsEveryDeliveryItCannotSendWithAReason(t *testing.T) {
496553
t.Parallel()
497554

0 commit comments

Comments
 (0)