|
8 | 8 | "net/http/httptest"
|
9 | 9 | "net/url"
|
10 | 10 | "testing"
|
| 11 | + "time" |
11 | 12 |
|
12 | 13 | "github.com/stretchr/testify/assert"
|
13 | 14 | "github.com/stretchr/testify/require"
|
@@ -84,6 +85,47 @@ func TestDERP(t *testing.T) {
|
84 | 85 | }
|
85 | 86 | })
|
86 | 87 |
|
| 88 | + t.Run("TimeoutCtx", func(t *testing.T) { |
| 89 | + t.Parallel() |
| 90 | + |
| 91 | + derpSrv := derp.NewServer(key.NewNode(), func(format string, args ...any) { t.Logf(format, args...) }) |
| 92 | + defer derpSrv.Close() |
| 93 | + srv := httptest.NewServer(derphttp.Handler(derpSrv)) |
| 94 | + defer srv.Close() |
| 95 | + |
| 96 | + var ( |
| 97 | + // nolint:gocritic // testing a deadline exceeded |
| 98 | + ctx, cancel = context.WithTimeout(context.Background(), time.Nanosecond) |
| 99 | + report = derphealth.Report{} |
| 100 | + derpURL, _ = url.Parse(srv.URL) |
| 101 | + opts = &derphealth.ReportOptions{ |
| 102 | + DERPMap: &tailcfg.DERPMap{Regions: map[int]*tailcfg.DERPRegion{ |
| 103 | + 1: { |
| 104 | + EmbeddedRelay: true, |
| 105 | + RegionID: 999, |
| 106 | + Nodes: []*tailcfg.DERPNode{{ |
| 107 | + Name: "1a", |
| 108 | + RegionID: 999, |
| 109 | + HostName: derpURL.Host, |
| 110 | + IPv4: derpURL.Host, |
| 111 | + STUNPort: -1, |
| 112 | + InsecureForTests: true, |
| 113 | + ForceHTTP: true, |
| 114 | + }}, |
| 115 | + }, |
| 116 | + }}, |
| 117 | + } |
| 118 | + ) |
| 119 | + cancel() |
| 120 | + |
| 121 | + report.Run(ctx, opts) |
| 122 | + |
| 123 | + assert.False(t, report.Healthy) |
| 124 | + if assert.NotNil(t, report.Error) { |
| 125 | + assert.Contains(t, context.DeadlineExceeded, *report.Error) |
| 126 | + } |
| 127 | + }) |
| 128 | + |
87 | 129 | t.Run("HealthyWithNodeDegraded", func(t *testing.T) {
|
88 | 130 | t.Parallel()
|
89 | 131 |
|
|
0 commit comments