-
Notifications
You must be signed in to change notification settings - Fork 943
fix(cli): ensure cliui.Agent
doesn't fetch infinitely
#8446
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
t.Run("NotInfinite", func(t *testing.T) { | ||
t.Parallel() | ||
var fetchCalled uint64 | ||
|
||
cmd := &clibase.Cmd{ | ||
Handler: func(inv *clibase.Invocation) error { | ||
buf := bytes.Buffer{} | ||
err := cliui.Agent(inv.Context(), &buf, uuid.Nil, cliui.AgentOptions{ | ||
FetchInterval: 10 * time.Millisecond, | ||
Fetch: func(ctx context.Context, agentID uuid.UUID) (codersdk.WorkspaceAgent, error) { | ||
atomic.AddUint64(&fetchCalled, 1) | ||
|
||
return codersdk.WorkspaceAgent{ | ||
Status: codersdk.WorkspaceAgentConnected, | ||
LifecycleState: codersdk.WorkspaceAgentLifecycleReady, | ||
}, nil | ||
}, | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
require.Never(t, func() bool { | ||
called := atomic.LoadUint64(&fetchCalled) | ||
return called > 5 || called == 0 | ||
}, time.Second, 100*time.Millisecond) | ||
|
||
return nil | ||
}, | ||
} | ||
require.NoError(t, cmd.Invoke().Run()) | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:chefs-kiss:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch, thanks for fixing this!
@@ -15,13 +15,16 @@ var errAgentShuttingDown = xerrors.New("agent is shutting down") | |||
|
|||
type AgentOptions struct { | |||
FetchInterval time.Duration | |||
Fetch func(context.Context) (codersdk.WorkspaceAgent, error) | |||
Fetch func(ctx context.Context, agentID uuid.UUID) (codersdk.WorkspaceAgent, error) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm glad you made this change too (to pass agent ID)!
Can confirm that starting lots of parallel |
Fixes: #8426