test / test (push) Canceled after 0s
The owner on the three things the reviews' commit left as found: can they be fixed? They can. - Downtime that crossed a UTC midnight was all booked on the day of the restart: it is cut at the midnights between (byDay). - A message with the null envelope sender - a bounce an application writes itself - left a refusal row without a domain, which no domain administrator would see: the row takes the domain the login is bound to. - A log read again after an unclean stop counted its deferrals again: while the tailer catches up, a warning no later than the last one counted is passed over. The mark is kept to the fraction of a second the log gives. And on the check being stricter than Postfix for an address with an extension (invoices+x@ passed in the envelope, was refused in the header): it makes Postfix's second try now, the address without its extension. recipient_delimiter was the distribution's default; it is set in postfix-config.sh, since the check depends on it. e2e sends one through. Test server, this tree: go vet ok, go test 23 packages ok, make e2e ok (339 s). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
69 lines
2.3 KiB
Go
69 lines
2.3 KiB
Go
package main
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
// The check's downtime is the time since its last mark, under a Postfix that
|
|
// was running: a new container has no mark, and a Postfix that is not up, or
|
|
// came up later than the mark, was not kept waiting by the check for all of
|
|
// that time.
|
|
func TestSenderCheckDowntime(t *testing.T) {
|
|
now := time.Date(2026, 10, 12, 18, 0, 0, 0, time.UTC)
|
|
mark := filepath.Join(t.TempDir(), "sender.sock.alive")
|
|
set := func(at time.Time) {
|
|
t.Helper()
|
|
if err := os.WriteFile(mark, nil, 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := os.Chtimes(mark, at, at); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
postfix := func(started time.Time, running bool) func() (time.Time, bool) {
|
|
return func() (time.Time, bool) { return started, running }
|
|
}
|
|
|
|
if d := senderCheckDowntime(mark, now, postfix(now.Add(-time.Hour), true)); d != 0 {
|
|
t.Errorf("no mark: %s", d)
|
|
}
|
|
set(now.Add(-40 * time.Second))
|
|
if d := senderCheckDowntime(mark, now, postfix(now.Add(-time.Hour), true)); d != 40*time.Second {
|
|
t.Errorf("Postfix up throughout: %s, want 40s", d)
|
|
}
|
|
if d := senderCheckDowntime(mark, now, postfix(now.Add(-10*time.Second), true)); d != 10*time.Second {
|
|
t.Errorf("Postfix started within the gap: %s, want 10s", d)
|
|
}
|
|
if d := senderCheckDowntime(mark, now, postfix(time.Time{}, false)); d != 0 {
|
|
t.Errorf("Postfix not running: %s", d)
|
|
}
|
|
set(now.Add(time.Minute)) // a clock set back
|
|
if d := senderCheckDowntime(mark, now, postfix(now.Add(-time.Hour), true)); d != 0 {
|
|
t.Errorf("a mark in the future: %s", d)
|
|
}
|
|
}
|
|
|
|
// Downtime is booked on the days it fell on.
|
|
func TestByDay(t *testing.T) {
|
|
at := func(d, h, m int) time.Time { return time.Date(2026, 10, d, h, m, 0, 0, time.UTC) }
|
|
got := byDay(at(12, 23, 50), at(14, 0, 10))
|
|
want := []dayPart{{at(12, 23, 50), 10 * time.Minute}, {at(13, 0, 0), 24 * time.Hour}, {at(14, 0, 0), 10 * time.Minute}}
|
|
if len(got) != len(want) {
|
|
t.Fatalf("parts = %+v", got)
|
|
}
|
|
for i := range want {
|
|
if !got[i].day.Equal(want[i].day) || got[i].down != want[i].down {
|
|
t.Errorf("part %d = %+v, want %+v", i, got[i], want[i])
|
|
}
|
|
}
|
|
if one := byDay(at(12, 10, 0), at(12, 10, 0).Add(40*time.Second)); len(one) != 1 || one[0].down != 40*time.Second {
|
|
t.Errorf("within a day: %+v", one)
|
|
}
|
|
if none := byDay(at(12, 10, 0), at(12, 10, 0)); len(none) != 0 {
|
|
t.Errorf("no time: %+v", none)
|
|
}
|
|
}
|