Files
selfpost/cmd/panel/sendercheck_test.go
T
mixandClaude Opus 5.5 bdeb01681d local-time: the panel in the container's zone, named on Settings
Agreed by the owner on 2026-10-13 (the local day, no "UTC" beside a
time); the zone is the container's TZ in .env and Settings only shows it,
his "Да" of 2026-10-17. Mockups c205106.

Every time the panel shows is formatted in time.Local and says no zone:
the logs' Time and the DMARC Received columns, a message's timeline,
Overview's "Updated", Health's certificate and renewal, the filter lists,
DMARC reports and windows, the auto limit's last recalculation. Stored
instants stay UTC. The days counted are the zone's: delivery_log_days and
sender_check_days key their rows by the local date, the sender check cuts
downtime at local midnights (byDay), the log filters' days run from local
midnight to local midnight. Notification mail and the test message write
the zone's abbreviation after a time - they are read away from the panel.
DMARC's one-day window label stays the reporter's (UTC) day.

Settings box 05, Time zone, read-only: the name (UTC without TZ), its
offset, and a TZ the image cannot load said to leave the times in UTC
(time/zoneinfo_unix.go, initLocal) rather than named. TZ is passed by the
compose file ("${TZ:-}"), in .env.example and the guide's table; tzdata is
named in the image (supervisor's python3.13 brings it today). Postfix
takes TZ through import_environment, so mail.log's stamps are the same
zone, which closes the trap the roadmap wrote down: the tailer has always
read them in time.Local.

Tests: a TestMain runs view, handlers, store and cmd/panel in UTC whatever
the machine's zone (as logtail's); TestSettingsShowsTheTimeZone,
TestTimesAreTheContainersZone, TestByDayInTheContainersZone, a Moscow day
in TestQueryInboundSpamFilters; envdoc's pattern takes two-letter names.
e2e time_zone_is_the_containers recreates the stand with
TZ=Europe/Moscow: date says MSK, Settings names the zone and UTC+03:00, a
test message's page gives its time and its mail.log lines in Moscow's.
go vet + go test (26 packages) and make e2e on the test server for this
tree.

Docs: guide (§ Settings, the TZ row, the days of Health and the logs),
architecture, schema-migrations, help (word for word with the mockup),
CHANGELOG [Unreleased] § Added, roadmap row done with the decision.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-17 01:34:28 +03:00

77 lines
3.0 KiB
Go

package main
import (
"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)
var mark time.Time // the alive mark's time; zero is no mark
set := func(at time.Time) { mark = at }
postfix := func(started time.Time, running bool) func() postfixState {
return func() postfixState { return postfixState{started: started, running: running, known: true} }
}
silent := func() postfixState { return postfixState{} }
down := func(ask func() postfixState) (time.Duration, bool) { return senderCheckDowntime(mark, now, ask) }
if d, _ := down(postfix(now.Add(-time.Hour), true)); d != 0 {
t.Errorf("no mark: %s", d)
}
set(now.Add(-40 * time.Second))
if d, est := down(postfix(now.Add(-time.Hour), true)); d != 40*time.Second || est {
t.Errorf("Postfix up throughout: %s %v, want 40s, not estimated", d, est)
}
if d, _ := down(postfix(now.Add(-10*time.Second), true)); d != 10*time.Second {
t.Errorf("Postfix started within the gap: %s, want 10s", d)
}
if d, _ := down(postfix(time.Time{}, false)); d != 0 {
t.Errorf("Postfix not running: %s", d)
}
// supervisord did not answer: the time since the mark, an estimate.
if d, est := down(silent); d != 40*time.Second || !est {
t.Errorf("supervisord silent: %s %v, want 40s, estimated", d, est)
}
set(now.Add(time.Minute)) // a clock set back
if d, _ := down(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)
}
}
// In a container with TZ=Europe/Moscow a day is Moscow's: an outage from
// 20:50 to 21:10 UTC crosses its midnight (21:00 UTC).
func TestByDayInTheContainersZone(t *testing.T) {
inZone(t, "Europe/Moscow")
from := time.Date(2026, 10, 12, 20, 50, 0, 0, time.UTC)
got := byDay(from, from.Add(20*time.Minute))
if len(got) != 2 || got[0].down != 10*time.Minute || got[1].down != 10*time.Minute ||
got[1].day.Format("2006-01-02 15:04") != "2026-10-13 00:00" {
t.Errorf("parts = %+v, want ten minutes on the 12th and ten from Moscow's midnight", got)
}
}