Skip to content

Commit 55eb07a

Browse files
committed
test(logs): avoid t.TempDir cleanup race on Windows for open log handle
The lumberjack writer keeps the per-server log file open for the logger's lifetime, and Windows cannot remove an open file. t.TempDir's cleanup asserts RemoveAll succeeds, failing the Cross-Platform Logging Tests job on windows-latest. Switch to os.MkdirTemp with a best-effort cleanup (mirroring TestE2E_LogRotation) and stop asserting on Sync(). Related #598
1 parent 088e41b commit 55eb07a

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

internal/logs/logger_test.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,14 @@ func TestServerLogFilename_SanitizesPathSeparators(t *testing.T) {
4242
// must produce a single flat log file, not a nested directory, and the tail
4343
// reader must round-trip the same raw name back to that file.
4444
func TestCreateUpstreamServerLogger_NamespacedNameFlatFile(t *testing.T) {
45-
logDir := t.TempDir()
45+
// Use os.MkdirTemp (not t.TempDir) with a best-effort cleanup: the lumberjack
46+
// writer keeps the log file handle open for the lifetime of the logger, and
47+
// Windows cannot remove an open file. t.TempDir's cleanup asserts RemoveAll
48+
// succeeds and would fail the test on Windows; a non-asserting cleanup mirrors
49+
// the existing TestE2E_LogRotation pattern.
50+
logDir, err := os.MkdirTemp("", "mcpproxy-logtest-*")
51+
require.NoError(t, err)
52+
t.Cleanup(func() { _ = os.RemoveAll(logDir) })
4653
const serverName = "io.github.evidai/polymarket-guard"
4754

4855
cfg := DefaultLogConfig()
@@ -53,7 +60,7 @@ func TestCreateUpstreamServerLogger_NamespacedNameFlatFile(t *testing.T) {
5360
logger, err := CreateUpstreamServerLogger(cfg, serverName)
5461
require.NoError(t, err)
5562
logger.Info("hello from polymarket-guard")
56-
require.NoError(t, logger.Sync())
63+
_ = logger.Sync()
5764

5865
// The flat file exists directly in logDir.
5966
flatPath := filepath.Join(logDir, "server-io.github.evidai_polymarket-guard.log")

0 commit comments

Comments
 (0)