usage: TestRowTokensAndZoneKept compares the zone by name and offset

The test compared got.Time.Location() with its own *time.Location by
pointer. rowZones keeps the first zone it sees for a name and offset, so
under -count=3 the second run got the first run's location back and the
test went red on unchanged code. It now checks the zone's name and
offset (IST, +5:30), which is what rowZones promises.

Run on mote: go test ./internal/usage -count=1 ok; -run
TestRowTokensAndZoneKept -count=3 ok (red on the old test). Broken by
hand: writing the row with an "XST" zone turns it red.
This commit is contained in:
yetone
2026-11-09 23:56:13 +08:00
parent 92be1d779b
commit 3a5e4b62d0
+4 -1
View File
@@ -84,7 +84,10 @@ func TestRowTokensAndZoneKept(t *testing.T) {
if got.Input != math.MaxInt32 || got.Output != math.MinInt32 || got.CacheRead != 7 {
t.Fatalf("read back Input %d, Output %d, CacheRead %d; want %d, %d, 7", got.Input, got.Output, got.CacheRead, math.MaxInt32, math.MinInt32)
}
if !got.Time.Equal(at) || got.Time.Location() != zone || got.Time.Format(time.RFC3339Nano) != at.Format(time.RFC3339Nano) {
// the zone by its name and offset, as rowZones knows it: a run
// before this one in the process (-count) made the zone kept
name, offset := got.Time.Zone()
if !got.Time.Equal(at) || name != "IST" || offset != 5*3600+1800 || got.Time.Format(time.RFC3339Nano) != at.Format(time.RFC3339Nano) {
t.Fatalf("read back time %v in %v, want %v", got.Time, got.Time.Location(), at)
}
if z := c.row(1).Time; !z.IsZero() {