Skip to content

Commit

Permalink
cmd/watcher: make mac tests pass
Browse files Browse the repository at this point in the history
  • Loading branch information
kortschak committed Dec 21, 2023
1 parent 2be2552 commit 82f2555
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 18 deletions.
34 changes: 16 additions & 18 deletions cmd/watcher/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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}}}]
:
[{}]`,
Expand All @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions cmd/watcher/poll_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 82f2555

Please sign in to comment.