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:
Cian Johnston
2024-06-07 10:01:54 +01:00
committed by GitHub
parent 7c3b8b6224
commit 48ecee1025
3 changed files with 48 additions and 4 deletions

View File

@ -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{}

View File

@ -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()