TestGatewayModeStatsNameTheGatewaySessions wrote its record at
time.Now()-1h, which in the first hour of a local day is yesterday, so
days=1 left it out: red on macOS and ubuntu CI at 4167419ab (00:31 UTC)
and on mote at 00:40 PST (#5690). The test now runs in a testing/synctest
bubble whose clock is moved to the next local 00:30, writes the record at
that moment, and checks the clock didn't move during the queries. A usage
test pins GatewaySessionWindow's edge: a local midnight is left out, one
nanosecond after it is in, on two consecutive days.
skygunner's patch (1554065a on their fork, posted on #5690 on 11-08),
applied as written on origin/main e12244aca; it waited three days unported.
Run on mote at this tree:
- The old fixture (-1h) inside the bubble: red at days=1 (TZ=UTC).
- -race -count=3 of both tests in UTC, America/Los_Angeles,
Asia/Shanghai and Australia/Sydney: ok.
- go test -tags nogui ./internal/gui ./internal/usage: ok; go vet ok;
gofmt -l clean.
Not run: the full suite (test-only change).
Co-authored-by: skygunner <skygunner@users.noreply.github.com>
42 lines
1.1 KiB
Go
42 lines
1.1 KiB
Go
package usage
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
// A gateway window excludes its local midnight, including after the day rolls over.
|
|
func TestGatewaySessionWindowMidnight(t *testing.T) {
|
|
resetUsageTest(t)
|
|
midnight := time.Date(2026, 10, 7, 0, 0, 0, 0, time.Local)
|
|
next := midnight.AddDate(0, 0, 1)
|
|
for _, record := range []struct {
|
|
id string
|
|
at time.Time
|
|
}{
|
|
{"at-start", midnight},
|
|
{"after-start", midnight.Add(time.Nanosecond)},
|
|
{"at-next", next},
|
|
{"after-next", next.Add(time.Nanosecond)},
|
|
} {
|
|
Append(Record{Time: record.at, Agent: "pi", Session: record.id, Provider: "p", Model: "m", Input: 1, Status: 200})
|
|
}
|
|
for _, test := range []struct {
|
|
since time.Time
|
|
want map[string]bool
|
|
}{
|
|
{midnight, map[string]bool{"after-start": true, "at-next": true, "after-next": true}},
|
|
{next, map[string]bool{"after-next": true}},
|
|
} {
|
|
got, _ := GatewaySessionWindow(test.since)
|
|
if len(got) != len(test.want) {
|
|
t.Fatalf("since %v: got %+v, want %v", test.since, got, test.want)
|
|
}
|
|
for _, session := range got {
|
|
if !test.want[session.ID] {
|
|
t.Fatalf("since %v: unexpected session %s", test.since, session.ID)
|
|
}
|
|
}
|
|
}
|
|
}
|