Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

chore(cli): address cli netcheck test flake#13492

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
johnstcn merged 3 commits intomainfromcj/flake/cli-healthcheck
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes fromall commits
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
4 changes: 2 additions & 2 deletionscli/netcheck_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,7 +5,6 @@ import (
"encoding/json"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/coder/coder/v2/cli/clitest"
Expand All@@ -30,7 +29,8 @@ func TestNetcheck(t *testing.T) {
var report healthsdk.DERPHealthReport
require.NoError(t, json.Unmarshal(b, &report))

assert.True(t, report.Healthy)
// We do not assert that the report is healthy, just that
// it has the expected number of reports per region.
require.Len(t, report.Regions, 1+1) // 1 built-in region + 1 test-managed STUN region
for _, v := range report.Regions {
require.Len(t, v.NodeReports, len(v.Region.Nodes))
Expand Down
8 changes: 6 additions & 2 deletionscoderd/healthcheck/derphealth/derp.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -236,8 +236,12 @@ func (r *NodeReport) derpURL() *url.URL {
}

func (r *NodeReport) Run(ctx context.Context) {
ctx, cancel := context.WithTimeout(ctx, 10*time.Second)
defer cancel()
// If there already is a deadline set on the context, do not override it.
if _, ok := ctx.Deadline(); !ok {
dCtx, cancel := context.WithTimeout(ctx, 10*time.Second)
defer cancel()
ctx = dCtx
}

r.Severity = health.SeverityOK
r.ClientLogs = [][]string{}
Expand Down
40 changes: 40 additions & 0 deletionscoderd/healthcheck/derphealth/derp_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -8,6 +8,7 @@ import (
"net/http/httptest"
"net/url"
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand DownExpand Up@@ -84,6 +85,45 @@ func TestDERP(t *testing.T) {
}
})

t.Run("TimeoutCtx", func(t *testing.T) {
t.Parallel()

derpSrv := derp.NewServer(key.NewNode(), func(format string, args ...any) { t.Logf(format, args...) })
defer derpSrv.Close()
srv := httptest.NewServer(derphttp.Handler(derpSrv))
defer srv.Close()

var (
// nolint:gocritic // testing a deadline exceeded
ctx, cancel = context.WithTimeout(context.Background(), time.Nanosecond)
report = derphealth.Report{}
derpURL, _ = url.Parse(srv.URL)
opts = &derphealth.ReportOptions{
DERPMap: &tailcfg.DERPMap{Regions: map[int]*tailcfg.DERPRegion{
1: {
EmbeddedRelay: true,
RegionID: 999,
Nodes: []*tailcfg.DERPNode{{
Name: "1a",
RegionID: 999,
HostName: derpURL.Host,
IPv4: derpURL.Host,
STUNPort: -1,
InsecureForTests: true,
ForceHTTP: true,
}},
},
}},
}
)
cancel()

report.Run(ctx, opts)

assert.False(t, report.Healthy)
assert.Nil(t, report.Error)
})

t.Run("HealthyWithNodeDegraded", func(t *testing.T) {
t.Parallel()

Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp