From 82f2555f2c348f4049e4724c73155b0727c6f2b2 Mon Sep 17 00:00:00 2001 From: Dan Kortschak Date: Fri, 22 Dec 2023 09:13:55 +1030 Subject: [PATCH] cmd/watcher: make mac tests pass --- cmd/watcher/main_test.go | 34 ++++++++++++++++------------------ cmd/watcher/poll_darwin.go | 1 + 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/cmd/watcher/main_test.go b/cmd/watcher/main_test.go index fe0a174..e76b2ad 100644 --- a/cmd/watcher/main_test.go +++ b/cmd/watcher/main_test.go @@ -130,24 +130,8 @@ func TestDaemon(t *testing.T) { }, }) - const changes = 5 - changeWg.Add(changes) - go func() { - for i := 0; i < changes; i++ { - time.Sleep(time.Second) - cmd := execabs.Command(testerPath, "-title", fmt.Sprintf("tester:%d", i)) - err := cmd.Start() - if err != nil { - t.Errorf("failed to start terminal %d", i) - } - t.Cleanup(func() { - cmd.Process.Kill() - }) - } - }() - t.Run("configure", func(t *testing.T) { - period := &rpc.Duration{Duration: time.Second} + period := &rpc.Duration{Duration: time.Second / 2} beat := &rpc.Duration{Duration: 5 * time.Second} var resp rpc.Message[string] @@ -163,7 +147,7 @@ func TestDaemon(t *testing.T) { Heartbeat: beat, Rules: map[string]string{ "change": ` - name.contains('tester') && window_id != last.window_id ? + name.contains('tester') && (window_id != last.window_id || window != last.window) ? [{"method":"change","params":{"page":"tester","details":{"name":name,"window":window}}}] : [{}]`, @@ -183,6 +167,20 @@ func TestDaemon(t *testing.T) { } }) + const changes = 5 + changeWg.Add(changes) + go func() { + for i := 0; i < changes; i++ { + cmd := execabs.Command(testerPath, "-title", fmt.Sprintf("tester:%d", i)) + err := cmd.Start() + if err != nil { + t.Errorf("failed to start terminal %d", i) + } + time.Sleep(time.Second) + cmd.Process.Kill() + } + }() + time.Sleep(10 * time.Second) // Let some updates and heartbeats past. t.Run("stop", func(t *testing.T) { diff --git a/cmd/watcher/poll_darwin.go b/cmd/watcher/poll_darwin.go index 0b1b6ac..cf7bfe2 100644 --- a/cmd/watcher/poll_darwin.go +++ b/cmd/watcher/poll_darwin.go @@ -101,6 +101,7 @@ func activeWindow() (watcher.Details, error) { // Could not get window exact details name, but return what we have. err = warning{fmt.Errorf("failed to obtain some details: missing application or window name: %w", err)} } + fmt.Printf("%#v\n", active) return active, err }