Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feat: Add connection_timeout and troubleshooting_url to agent #4937

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

Merged
merged 11 commits into from
Nov 9, 2022
Prev Previous commit
Next Next commit
Add coderd testcase for coder agent timeout
  • Loading branch information
mafredri committed Nov 9, 2022
commit 788c1f4c4ece9b4a8a85f5d9d00ff992f7772b46
47 changes: 47 additions & 0 deletions coderd/workspaceagents_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,53 @@ func TestWorkspaceAgent(t *testing.T) {
_, err = client.WorkspaceAgent(ctx, workspace.LatestBuild.Resources[0].Agents[0].ID)
require.NoError(t, err)
})
t.Run("Timeout", func(t *testing.T) {
t.Parallel()
client := coderdtest.New(t, &coderdtest.Options{
IncludeProvisionerDaemon: true,
})
user := coderdtest.CreateFirstUser(t, client)
authToken := uuid.NewString()
tmpDir := t.TempDir()
version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, &echo.Responses{
Parse: echo.ParseComplete,
ProvisionDryRun: echo.ProvisionComplete,
Provision: []*proto.Provision_Response{{
Type: &proto.Provision_Response_Complete{
Complete: &proto.Provision_Complete{
Resources: []*proto.Resource{{
Name: "example",
Type: "aws_instance",
Agents: []*proto.Agent{{
Id: uuid.NewString(),
Directory: tmpDir,
Auth: &proto.Agent_Token{
Token: authToken,
},
ConnectionTimeout: 1,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: question about the naming conversion, it seems that ConnectionTimeout is reserved only for seconds, should we name this ConnectionTimeoutSec? I hope that we won't need a 500ms timeout in the future :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a bad suggestion at all. I'm a bit vary of doing it though since this value is propagated through terraform-provider-coder, I was following the previous convention for how an int/second is represented in the code (e.g. codersdk.Healthcheck.Interval).

We do have other places in the code that utilizes *Millis/_ms, however. So there is precedent for both.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So there is precedent for both

Good for me, thanks!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be worth opening an issue to standardize these fields @mafredri... it makes me significantly more nervous about working with code with unspecified durations. The change of course doesn't need to happen in this PR though!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll create the issue for standardization tomorrow, I did however push the change for this PR in a182cdf already, turned out much better. Thanks for pushing for this change both of you. 👍🏻

TroubleshootingUrl: "https://example.com/troubleshoot",
}},
}},
},
},
}},
})
template := coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID)
coderdtest.AwaitTemplateVersionJob(t, client, version.ID)
workspace := coderdtest.CreateWorkspace(t, client, user.OrganizationID, template.ID)
coderdtest.AwaitWorkspaceBuildJob(t, client, workspace.LatestBuild.ID)

ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitMedium)
defer cancel()

testutil.Eventually(ctx, t, func(ctx context.Context) (done bool) {
workspace, err := client.Workspace(ctx, workspace.ID)
if !assert.NoError(t, err) {
return false
}
return workspace.LatestBuild.Resources[0].Agents[0].Status == codersdk.WorkspaceAgentTimeout
}, testutil.IntervalMedium, "agent status timeout")
})
}

func TestWorkspaceAgentListen(t *testing.T) {
Expand Down