Files
seaweedfs/seaweed-block/cmd/blockvolume/procedure_log_time_contract_test.go
T

37 lines
987 B
Go

//go:build linux && subprocess && chunkstore_integration
package main_test
import (
"os"
"path/filepath"
"testing"
"time"
)
func TestProcedureLogTimesUseTheUTCInstant(t *testing.T) {
old := time.Local
time.Local = time.FixedZone("UTC-8", -8*60*60)
defer func() { time.Local = old }()
const reason = "clock-skew margin has not elapsed"
for _, tc := range []struct {
name, stamp string
nanos int
}{
{"microseconds", "2026/11/29 05:12:42.123456", 123456000},
{"whole-second", "2026/11/29 05:12:42", 0},
} {
t.Run(tc.name, func(t *testing.T) {
path := filepath.Join(t.TempDir(), "holder.log")
if err := os.WriteFile(path, []byte(tc.stamp+" "+reason+"\n"), 0600); err != nil {
t.Fatal(err)
}
got := lastLogTime(&daemon{log: path}, reason)
want := time.Date(2026, 11, 29, 5, 12, 42, tc.nanos, time.UTC)
if !got.Equal(want) {
t.Fatalf("log instant %s; want %s", got.Format(time.RFC3339Nano), want.Format(time.RFC3339Nano))
}
})
}
}