mirror of
https://github.com/coder/coder.git
synced 2025-07-06 15:41:45 +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:
@ -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{}
|
||||
|
@ -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