mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 02:27:26 +01:00
test: compare procedure log times as precise UTC instants
This commit is contained in:
1 parent
a9f69b663f
commit
85ce02cb3b
3 files changed
+48
-7
No files matched your search
@@ -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
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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))
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user