mirror of
https://github.com/coder/coder.git
synced 2025-07-13 21:36:50 +00:00
chore(cli): address cli netcheck test flake (#13492)
* netcheck: removes check for healthy node report in test * coderd/healthcheck/derphealth: do not override parent context deadline
This commit is contained in:
@ -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"
|
||||
@ -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))
|
||||
|
@ -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)
|
||||
// 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{}
|
||||
|
@ -8,6 +8,7 @@ import (
|
||||
"net/http/httptest"
|
||||
"net/url"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
@ -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()
|
||||
|
||||
|
Reference in New Issue
Block a user