mirror of
https://github.com/jesseduffield/lazygit.git
synced 2026-10-05 21:46:49 -04:00
Fix occasionally failing integration test (#6088)
The integration test filter_and_search/search_a_long_diff fails now and then on CI with "Expected search prompt to be focused". Pressing "/" in the focused main view reads the rest of the diff with ReadToEnd. Its callback opens the prompt by enqueueing the work onto the UI thread. ReadToEnd marks its task as done before calling the callback, so for a moment no task is busy. If the idle wait of the test driver wakes up in that moment, the test checks for the prompt before it is open. Adding a sleep between the two calls makes the test fail every time. The same gap exists when going to the bottom of a view, since that callback enqueues its work onto the UI thread too. Call the callback first, and mark the task as done after it returns. The work that the callback enqueues holds a task of its own from the moment it is enqueued, so lazygit no longer counts as idle in between.
This commit is contained in:
+4
-2
@@ -213,13 +213,15 @@ func (self *ViewBufferManager) StartLoading() {
|
||||
|
||||
func (self *ViewBufferManager) ReadToEnd(then func()) {
|
||||
// The reading happens on the task's own goroutine, and the caller hears about
|
||||
// it through then, so lazygit must not count as idle in between.
|
||||
// it through then, so lazygit must not count as idle in between. The task is
|
||||
// done only once then has returned, because then typically hands its work to
|
||||
// the UI thread, and that work counts as busy only once it is enqueued.
|
||||
task := self.newGocuiTask()
|
||||
answered := func() {
|
||||
task.Done()
|
||||
if then != nil {
|
||||
then()
|
||||
}
|
||||
task.Done()
|
||||
}
|
||||
|
||||
request := LinesToRead{Total: -1, InitialRefreshAfter: -1, Then: answered}
|
||||
|
||||
@@ -522,3 +522,25 @@ func TestQueuedReadRequestsAreAnsweredWhenTheTaskStops(t *testing.T) {
|
||||
|
||||
assert.EqualValues(t, 2, answered.Load())
|
||||
}
|
||||
|
||||
// The callers of ReadToEnd hand their follow-up work to the UI thread from then, and
|
||||
// that work holds a task of its own from the moment it is enqueued. If the task that
|
||||
// ReadToEnd holds were done before then runs, lazygit would count as idle for a moment
|
||||
// in between, and an integration test would carry on before the follow-up work is done.
|
||||
func TestReadToEndHoldsItsTaskUntilThenReturns(t *testing.T) {
|
||||
noop := func() {}
|
||||
task := gocui.NewFakeTask()
|
||||
|
||||
manager := NewViewBufferManager(
|
||||
utils.NewDummyLog(), bytes.NewBuffer(nil), noop, noop, noop, noop, noop, noop,
|
||||
func() gocui.Task { return task },
|
||||
func(f func()) error { f(); return nil },
|
||||
)
|
||||
|
||||
// With no command task serving read requests, ReadToEnd answers right away.
|
||||
var statusDuringThen gocui.TaskStatus
|
||||
manager.ReadToEnd(func() { statusDuringThen = task.Status() })
|
||||
|
||||
assert.Equal(t, gocui.TaskStatusBusy, statusDuringThen)
|
||||
assert.Equal(t, gocui.TaskStatusDone, task.Status())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user