From a3b9f3c96155ac86049ee585acbb24d27a1153d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Victor=20Anderss=C3=A9n?= Date: Fri, 13 Feb 2026 20:43:40 +0200 Subject: [PATCH] fix: enhance waitForFile function to check for specific line content and improve timeout error messages --- cmd/client/voice_daemon_test.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/cmd/client/voice_daemon_test.go b/cmd/client/voice_daemon_test.go index fbeabd2..872f29c 100644 --- a/cmd/client/voice_daemon_test.go +++ b/cmd/client/voice_daemon_test.go @@ -20,19 +20,25 @@ func makeExecutableFile(t *testing.T, path string, content string) { } } -func waitForFile(t *testing.T, path string, timeout time.Duration) string { +func waitForFile(t *testing.T, path string, timeout time.Duration, wantLine string) string { t.Helper() deadline := time.Now().Add(timeout) for { data, err := os.ReadFile(path) if err == nil { - return string(data) + content := string(data) + if wantLine == "" || hasLine(content, wantLine) { + return content + } } if !errors.Is(err, os.ErrNotExist) { t.Fatalf("read %s: %v", path, err) } if time.Now().After(deadline) { - t.Fatalf("timed out waiting for %s", path) + if wantLine == "" { + t.Fatalf("timed out waiting for %s", path) + } + t.Fatalf("timed out waiting for %s to contain line %q", path, wantLine) } time.Sleep(20 * time.Millisecond) } @@ -142,14 +148,14 @@ func TestStartVoiceDaemonLaunchesProcessAndStops(t *testing.T) { t.Fatalf("expected voiceAutoStarting=true after start") } - argsOut := waitForFile(t, argsPath, 2*time.Second) + argsOut := waitForFile(t, argsPath, 2*time.Second, "--meter") for _, arg := range []string{"-server", "http://dialtone.test", "-token", "secret-token", "-ipc", "/tmp/dialtone-test.sock", "--meter"} { if !hasLine(argsOut, arg) { t.Fatalf("expected daemon arg %q in:\n%s", arg, argsOut) } } - envOut := waitForFile(t, envPath, 2*time.Second) + envOut := waitForFile(t, envPath, 2*time.Second, "DIALTONE_KEEP_ME=ok") if strings.Contains(envOut, "XDG_ACTIVATION_TOKEN=") { t.Fatalf("expected launcher token removed from daemon environment") }