Skip to content

Commit

Permalink
request_test: improve Dispatch test that opens multiple kitty instances
Browse files Browse the repository at this point in the history
  • Loading branch information
thiagokokada committed Jul 23, 2024
1 parent 34a75f0 commit 43df740
Showing 1 changed file with 33 additions and 2 deletions.
35 changes: 33 additions & 2 deletions request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"reflect"
"strings"
"testing"
"time"
)

var c *RequestClient
Expand Down Expand Up @@ -171,8 +172,38 @@ func TestDispatch(t *testing.T) {
if testing.Short() {
t.Skip("skip slow test")
}
testCommandRR(t, func() (RawResponse, error) {
return c.Dispatch(genParams("exec kitty sh -c 'exit 0'", 40)...)

// Testing if we can open at least the amount of instances we asked
// Dispatch() to open.
// The reason this test exist is because Hyprland has a hidden
// limitation in the total amount of batch commands you can trigger,
// but this is not documented and it also fails silently.
// So this test allows us to validate that the current split of
// batch commands is working as expected.
// See also: prepareRequests function and MAX_COMMANDS const
const want = 35
const retries = 10
t.Run(fmt.Sprintf("test_opening_%d_kitty_instances", want), func(t *testing.T) {
must1(c.Dispatch(genParams("exec kitty sh -c 'sleep 10 && exit 0'", want)...))
awid := must1(c.ActiveWorkspace()).Id
got := 0
for i := 0; i < retries; i++ {
got = 0
time.Sleep(1 * time.Second)
cls := must1(c.Clients())

for _, cl := range cls {
if cl.Workspace.Id == awid && cl.Class == "kitty" {
got += 1
}
}
if got >= want {
t.Logf("after retries: %d, got kitty: %d, finishing test", i+1, got)
return
}
}
// after maximum amount of retries, give up
t.Errorf("after retries: %d, got kitty: %d, want at least: %d", retries, got, want)
})
}

Expand Down

0 comments on commit 43df740

Please sign in to comment.