bisync: fix time.Local data race on tests - fixes #8272

Before this change, the bisync tests were directly setting the time.Local
variable to UTC.

The reason for overriding the time zone on the tests is to make them
deterministic regardless of where in the world the user happens to be. There are
some goldenized strings which have the time zone hard-coded and would result in a
miscompare failure outside of that time zone.

However, mutating the time.Local variable is not the right way to do this, as OP
correctly pointed out on #8272.

Setting the TZ environment variable from within the code was also not an ideal
solution because, while it worked on unix, it did not work on Windows. See
fbac94a799/src/time/zoneinfo.go (L79-L80)

This change fixes the issue by defining a new bisync.LogTZ setting for use when
printing timestamps in /cmd/bisync/resolve.go. We override this on the tests
instead of time.Local.
This commit is contained in:
nielash
2025-08-10 21:09:45 -04:00
parent be73a10a97
commit fc5bd21e28
3 changed files with 12 additions and 8 deletions

View File

@@ -226,6 +226,7 @@ var color = bisync.Color
// TestMain drives the tests
func TestMain(m *testing.M) {
bisync.LogTZ = time.UTC
fstest.TestMain(m)
}
@@ -277,7 +278,6 @@ func testBisync(t *testing.T, path1, path2 string) {
ci.RefreshTimes = true
}
bisync.Colors = true
time.Local = bisync.TZ
ci.FsCacheExpireDuration = fs.Duration(5 * time.Hour)
baseDir, err := os.Getwd()