mirror of
https://github.com/docker/compose.git
synced 2026-11-17 13:45:39 +00:00
fix(up): stop the menu loop when the keyboard channel is closed
keyboard.Close closes the channel handed out by GetKeys. Run kept reading zero-value events from it until its context was done. Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
parent
149cf98f5b
commit
7a34cdbaa6
2 changed files with 23 additions and 1 deletions
|
|
@ -327,7 +327,10 @@ func (lk *LogKeyboard) Run(ctx context.Context, project *types.Project, options
|
|||
select {
|
||||
case <-ctx.Done():
|
||||
return
|
||||
case event := <-lk.keys:
|
||||
case event, ok := <-lk.keys:
|
||||
if !ok { // the keyboard was closed
|
||||
return
|
||||
}
|
||||
lk.handleKeyEvent(ctx, event, project, options)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -60,6 +60,25 @@ func TestRunHandlesKeysUntilContextIsDone(t *testing.T) {
|
|||
assert.NilError(t, lk.Close(), "Close must be idempotent")
|
||||
}
|
||||
|
||||
func TestRunReturnsWhenKeyboardIsClosed(t *testing.T) {
|
||||
keys := make(chan keyboard.KeyEvent)
|
||||
lk := NewKeyboardManager(false, false, make(chan os.Signal, 1))
|
||||
lk.keys = keys
|
||||
|
||||
done := make(chan struct{})
|
||||
go func() {
|
||||
lk.Run(t.Context(), &types.Project{}, api.UpOptions{})
|
||||
close(done)
|
||||
}()
|
||||
|
||||
close(keys) // what keyboard.Close does to the channel it handed out
|
||||
select {
|
||||
case <-done:
|
||||
case <-time.After(5 * time.Second):
|
||||
t.Fatal("Run must return once the keyboard channel is closed")
|
||||
}
|
||||
}
|
||||
|
||||
func TestRunWithoutOpenReturnsImmediately(t *testing.T) {
|
||||
lk := NewKeyboardManager(false, false, make(chan os.Signal, 1))
|
||||
done := make(chan struct{})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue