From 85ce02cb3b24a2b2f2510834a792f699a5aa44fe Mon Sep 17 00:00:00 2001 From: pingqiu Date: Sat, 28 Nov 2026 21:48:56 -0800 Subject: [PATCH] test: compare procedure log times as precise UTC instants --- seaweed-block/.github/process-level-tests.txt | 3 ++ .../procedure_gate_integration_test.go | 16 +++++---- .../procedure_log_time_contract_test.go | 36 +++++++++++++++++++ 3 files changed, 48 insertions(+), 7 deletions(-) create mode 100644 seaweed-block/cmd/blockvolume/procedure_log_time_contract_test.go diff --git a/seaweed-block/.github/process-level-tests.txt b/seaweed-block/.github/process-level-tests.txt index 11ebf9a0e6..aeec6737dd 100644 --- a/seaweed-block/.github/process-level-tests.txt +++ b/seaweed-block/.github/process-level-tests.txt @@ -75,3 +75,6 @@ TestG15c_BlockCSICreateVolumeWritesMasterLifecycleIntent # package=blockcsi # Typed delete stdout remains separate from HEAD diagnostics. TestDeleteNoRevokeKeepsTheTypedStdoutSeparate + +# Procedure ordering compares the UTC log instant including its fraction. +TestProcedureLogTimesUseTheUTCInstant diff --git a/seaweed-block/cmd/blockvolume/procedure_gate_integration_test.go b/seaweed-block/cmd/blockvolume/procedure_gate_integration_test.go index 509c28195e..6fb6024f8d 100644 --- a/seaweed-block/cmd/blockvolume/procedure_gate_integration_test.go +++ b/seaweed-block/cmd/blockvolume/procedure_gate_integration_test.go @@ -290,14 +290,14 @@ func TestProcedureStartInsideTheBarrierWaitIsReGranted(t *testing.T) { t.Fatal("the returning holder never served within 90 s") } // Started before the barrier, its renewals must have been refused for it - // at least once; log times have 1 s resolution. + // at least once; the UTC log timestamp retains its microseconds. last := lastLogTime(back, "clock-skew margin has not elapsed") if last.IsZero() { t.Fatal("started 40 s after the stop, the returning holder logged no renewal refused for the barrier") } - if ready[0].Before(last.Add(time.Second)) { + if ready[0].Before(last) { t.Errorf("the returning holder served at %s, while its renewal was still refused for the barrier at %s: it served without a lease", - ready[0].Format("15:04:05.000"), last.Format("15:04:05")) + ready[0].Format("15:04:05.000"), last.Format("15:04:05.000000")) } if !back.has("workspace lease: re-granted after ") { t.Error("the returning holder served without logging its re-grant") @@ -310,14 +310,16 @@ func TestProcedureStartInsideTheBarrierWaitIsReGranted(t *testing.T) { } } -// lastLogTime is the time of the last log line containing s (second -// resolution, the log's local time), or zero. +// lastLogTime is the UTC instant of the last standard log line containing s, +// retaining its fractional seconds, or zero. The process log uses UTC even when +// the test runner's local timezone differs. func lastLogTime(d *daemon, s string) time.Time { data, _ := os.ReadFile(d.log) var last time.Time for _, l := range strings.Split(string(data), "\n") { - if strings.Contains(l, s) && len(l) >= 19 { - if ts, err := time.ParseInLocation("2006/01/02 15:04:05", l[:19], time.Local); err == nil { + fields := strings.Fields(l) + if strings.Contains(l, s) && len(fields) >= 2 { + if ts, err := time.ParseInLocation("2006/01/02 15:04:05.999999", fields[0]+" "+fields[1], time.UTC); err == nil { last = ts } } diff --git a/seaweed-block/cmd/blockvolume/procedure_log_time_contract_test.go b/seaweed-block/cmd/blockvolume/procedure_log_time_contract_test.go new file mode 100644 index 0000000000..fbc987b76a --- /dev/null +++ b/seaweed-block/cmd/blockvolume/procedure_log_time_contract_test.go @@ -0,0 +1,36 @@ +//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)) + } + }) + } +}