Skip to content

Commit

Permalink
Fix flakey test
Browse files Browse the repository at this point in the history
I've simplifiied the code because it was too complex for the current requirements, and this fixed the misc/initial_open
test which was occasionally failing due to a race condition around busy tasks
  • Loading branch information
jesseduffield committed Jul 10, 2023
1 parent 2161a8e commit ee18bfc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 30 deletions.
40 changes: 13 additions & 27 deletions pkg/gui/gui.go
Original file line number Diff line number Diff line change
Expand Up @@ -780,37 +780,23 @@ func (gui *Gui) loadNewRepo() error {
return nil
}

func (gui *Gui) showInitialPopups(popupTasks []func(chan struct{}) error) {
gui.waitForIntro.Add(len(popupTasks))
done := make(chan struct{})

gui.c.OnWorker(func(task gocui.Task) {
for _, popupTask := range popupTasks {
if err := popupTask(done); err != nil {
_ = gui.c.Error(err)
}
func (gui *Gui) showIntroPopupMessage() {
gui.waitForIntro.Add(1)

task.Pause()
<-done
task.Continue()
gui.c.OnUIThread(func() error {
onConfirm := func() error {
gui.c.GetAppState().StartupPopupVersion = StartupPopupVersion
err := gui.c.SaveAppState()
gui.waitForIntro.Done()
return err
}
})
}

func (gui *Gui) showIntroPopupMessage(done chan struct{}) error {
onConfirm := func() error {
gui.c.GetAppState().StartupPopupVersion = StartupPopupVersion
err := gui.c.SaveAppState()
done <- struct{}{}
return err
}

return gui.c.Confirm(types.ConfirmOpts{
Title: "",
Prompt: gui.c.Tr.IntroPopupMessage,
HandleConfirm: onConfirm,
HandleClose: onConfirm,
return gui.c.Confirm(types.ConfirmOpts{
Title: "",
Prompt: gui.c.Tr.IntroPopupMessage,
HandleConfirm: onConfirm,
HandleClose: onConfirm,
})
})
}

Expand Down
4 changes: 1 addition & 3 deletions pkg/gui/layout.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,12 +213,10 @@ func (gui *Gui) onInitialViewsCreation() error {
gui.g.Mutexes.ViewsMutex.Unlock()

if !gui.c.UserConfig.DisableStartupPopups {
popupTasks := []func(chan struct{}) error{}
storedPopupVersion := gui.c.GetAppState().StartupPopupVersion
if storedPopupVersion < StartupPopupVersion {
popupTasks = append(popupTasks, gui.showIntroPopupMessage)
gui.showIntroPopupMessage()
}
gui.showInitialPopups(popupTasks)
}

if gui.showRecentRepos {
Expand Down

0 comments on commit ee18bfc

Please sign in to comment.