internal/control/loginlink_test.go
31 lines · 1393 bytes
1package control
2
3import (
4 "testing"
5 "time"
6
7 // Aliased: this package already has a top-level function named notify
8 // (notifications.go), which the default import name would collide with.
9 mailqueue "gitbay.org/gitbay/internal/notify"
10)
11
12// Nothing ties notify's retry parameters to loginLinkTTL: someone tuning
13// mail retries for a slow relay has no reason to think about login links,
14// and the failure if they drift apart is silent — a link delivered after
15// it has already expired, refused with no indication why. This computes
16// the mailer's worst-case delivery time from notify's own named constants
17// (attempts 1..MaxAttempts-1 each wait RetryBase<<(attempt-1); the
18// MaxAttempts'th failure is dead-lettered immediately, per notify.Mailer.Run)
19// rather than a copy of the numbers, so either side moving breaks this test.
20func TestLoginLinkOutlivesMailerRetries(t *testing.T) {
21 var worst time.Duration
22 for attempt := 1; attempt < mailqueue.DefaultMaxAttempts; attempt++ {
23 worst += mailqueue.DefaultRetryBase << (attempt - 1)
24 }
25 if worst >= loginLinkTTL {
26 t.Fatalf("mailqueue.DefaultRetryBase=%s, mailqueue.DefaultMaxAttempts=%d: worst-case "+
27 "delivery is %s, not less than loginLinkTTL=%s — a retried login link mail can "+
28 "arrive after the link it carries has expired",
29 mailqueue.DefaultRetryBase, mailqueue.DefaultMaxAttempts, worst, loginLinkTTL)
30 }
31}