File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -13,6 +13,8 @@ import (
1313
1414var ErrUpdateUnavailable = errors .New ("update check unavailable" )
1515
16+ const lcuStateRefreshTimeout = 750 * time .Millisecond
17+
1618type (
1719 ServiceFactory func (RuntimeConfig ) (autobuild.Service , error )
1820 LCUStatusProvider func (context.Context , RuntimeConfig ) LCUStatus
@@ -131,7 +133,9 @@ func (a *App) State(ctx context.Context) ViewState {
131133 if a .coachlessAuth != nil {
132134 state .CoachlessAuth = cloneCoachlessAuthState (a .coachlessAuth .Status (ctx ))
133135 }
134- state .LCU = a .lcuStatus (ctx , configSnapshot )
136+ statusCtx , cancel := context .WithTimeout (ctx , lcuStateRefreshTimeout )
137+ state .LCU = a .lcuStatus (statusCtx , configSnapshot )
138+ cancel ()
135139
136140 return state
137141}
Original file line number Diff line number Diff line change @@ -384,6 +384,29 @@ func TestStateCopiesCoachlessAuthState(t *testing.T) {
384384 }
385385}
386386
387+ func TestStateBoundsLCUStatusRefresh (t * testing.T ) {
388+ app := newTestApp (t , testAppOptions {
389+ lcuStatus : func (ctx context.Context , _ RuntimeConfig ) LCUStatus {
390+ <- ctx .Done ()
391+ return LCUStatus {State : LCUConnectionStateNotConnected , Message : ctx .Err ().Error ()}
392+ },
393+ })
394+
395+ start := time .Now ()
396+ state := app .State (context .Background ())
397+ elapsed := time .Since (start )
398+
399+ if elapsed > lcuStateRefreshTimeout + 500 * time .Millisecond {
400+ t .Fatalf ("State() took %v, want bounded by LCU state refresh timeout" , elapsed )
401+ }
402+ if state .LCU .State != LCUConnectionStateNotConnected {
403+ t .Fatalf ("LCU state = %q, want not_connected" , state .LCU .State )
404+ }
405+ if state .LCU .Message != context .DeadlineExceeded .Error () {
406+ t .Fatalf ("LCU message = %q, want deadline exceeded" , state .LCU .Message )
407+ }
408+ }
409+
387410func TestCoachlessAuthActionsUseSessionWithoutSavingConfig (t * testing.T ) {
388411 store := & recordingConfigStore {}
389412 authSession := & stubCoachlessAuth {
You can’t perform that action at this time.
0 commit comments