Skip to content

chore: retry healthcheck in proxy region test #10729

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 2 commits into from
Nov 16, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
chore: retry healthcheck in proxy region test
  • Loading branch information
deansheather committed Nov 16, 2023
commit 8ad494e084aab83ca1c23f360c21597f3e673386
40 changes: 34 additions & 6 deletions enterprise/coderd/workspaceproxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/coder/coder/v2/enterprise/wsproxy/wsproxysdk"
"github.com/coder/coder/v2/provisioner/echo"
"github.com/coder/coder/v2/testutil"
"github.com/coder/retry"
)

func TestRegions(t *testing.T) {
Expand Down Expand Up @@ -115,13 +116,40 @@ func TestRegions(t *testing.T) {
proxy, err := db.GetWorkspaceProxyByName(ctx, proxyName)
require.NoError(t, err)

// Refresh proxy health.
err = api.ProxyHealth.ForceUpdate(ctx)
require.NoError(t, err)
// Refresh proxy health until it's healthy.
var regions []codersdk.Region
for r := retry.New(time.Millisecond*10, time.Second*5); r.Wait(ctx); {
err = api.ProxyHealth.ForceUpdate(ctx)
require.NoError(t, err)

regions, err := client.Regions(ctx)
require.NoError(t, err)
require.Len(t, regions, 2)
regions, err = client.Regions(ctx)
require.NoError(t, err)
require.Len(t, regions, 2)

// All regions should be healthy, otherwise try updating again.
healthy := true
for _, region := range regions {
if region.Healthy {
continue
}

// Log the healthcheck failure reason.
wp, err := client.WorkspaceProxyByID(ctx, region.ID)
require.NoError(t, err)
t.Logf("region %q is not healthy yet, retrying healthcheck", region.Name)
for _, errMsg := range wp.Status.Report.Errors {
t.Logf(" - error: %s", errMsg)
}
for _, warnMsg := range wp.Status.Report.Warnings {
t.Logf(" - warning: %s", warnMsg)
}
healthy = false
break
}
if healthy {
break
}
}

// Region 0 is the primary require.Len(t, regions, 1)
require.NotEqual(t, uuid.Nil, regions[0].ID)
Expand Down