Skip to content

Commit 45a529f

Browse files
committed
fix: Adding upper bound for driveModel loop
1 parent 0c207c4 commit 45a529f

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

internal/cli/commands/catalog/tui/redesign/synctest_helpers_test.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ import (
1313
// loadFunc sleeps) so synctest can drain the bubble.
1414
const settleTimeout = 10 * time.Second
1515

16+
// settleMaxIterations is a defensive cap on the drain loop in driveModel. The
17+
// fake-clock deadline already bounds the loop in practice, but this guards
18+
// against pathological cases where each iteration fails to advance the clock
19+
// (e.g. a misbehaving cmd that re-arms itself instantly).
20+
const settleMaxIterations = 10_000
21+
1622
// driveModel runs a synctest-friendly mini bubbletea loop against m. It is a
1723
// drop-in stand-in for tea.NewProgram when tests want fake time instead of
1824
// real wall-clock waits.
@@ -126,8 +132,9 @@ func driveModel(t *testing.T, m tea.Model, width, height int, interact []tea.Msg
126132
// without dispatching to Update so cmd goroutines can send their
127133
// final message and exit.
128134
deadline := time.Now().Add(settleTimeout)
135+
iter := 0
129136

130-
for {
137+
for iter = range settleMaxIterations {
131138
synctest.Wait()
132139

133140
select {
@@ -143,5 +150,9 @@ func driveModel(t *testing.T, m tea.Model, width, height int, interact []tea.Msg
143150
time.Sleep(50 * time.Millisecond)
144151
}
145152

153+
if iter == settleMaxIterations-1 {
154+
t.Fatalf("driveModel: bubble did not settle within %d iterations; a cmd is likely re-arming itself instantly and preventing the fake clock from advancing", settleMaxIterations)
155+
}
156+
146157
return m
147158
}

0 commit comments

Comments
 (0)