Skip to content

Commit e5b33f5

Browse files
committed
chore: fix wsproxy test flake
1 parent 4cc132c commit e5b33f5

File tree

1 file changed

+23
-11
lines changed

1 file changed

+23
-11
lines changed

enterprise/wsproxy/wsproxy_test.go

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ func TestDERPEndToEnd(t *testing.T) {
344344
Name: "best-proxy",
345345
})
346346

347-
// Wait for the proxy to become healthy.
347+
// Wait for the proxy to become healthy and appear in the DERP map.
348348
require.Eventually(t, func() bool {
349349
healthCtx := testutil.Context(t, testutil.WaitLong)
350350
err := api.ProxyHealth.ForceUpdate(healthCtx)
@@ -367,17 +367,29 @@ func TestDERPEndToEnd(t *testing.T) {
367367
return true
368368
}, testutil.WaitLong, testutil.IntervalMedium)
369369

370-
// Swap out the DERPMapper for a fake one that only returns the proxy. This
371-
// allows us to force the agent to pick the proxy as its preferred region.
372-
oldDERPMapper := *api.AGPL.DERPMapper.Load()
373-
newDERPMapper := func(derpMap *tailcfg.DERPMap) *tailcfg.DERPMap {
374-
derpMap = oldDERPMapper(derpMap)
375-
// Strip everything but the proxy, which is region ID 10001.
376-
derpMap.Regions = map[int]*tailcfg.DERPRegion{
377-
10001: derpMap.Regions[10001],
370+
// Wait until the proxy appears in the DERP map, and then swap out the DERP
371+
// map for one that only contains the proxy region. This allows us to force
372+
// the agent to pick the proxy as its preferred region.
373+
var proxyOnlyDERPMap *tailcfg.DERPMap
374+
require.Eventually(t, func() bool {
375+
derpMap := api.AGPL.DERPMap()
376+
if derpMap == nil {
377+
return false
378+
}
379+
if _, ok := derpMap.Regions[10001]; !ok {
380+
return false
378381
}
379-
derpMap.OmitDefaultRegions = true
380-
return derpMap
382+
383+
// Make a DERP map that only contains the proxy region.
384+
proxyOnlyDERPMap = derpMap.Clone()
385+
proxyOnlyDERPMap.Regions = map[int]*tailcfg.DERPRegion{
386+
10001: proxyOnlyDERPMap.Regions[10001],
387+
}
388+
proxyOnlyDERPMap.OmitDefaultRegions = true
389+
return true
390+
}, testutil.WaitLong, testutil.IntervalMedium)
391+
newDERPMapper := func(derpMap *tailcfg.DERPMap) *tailcfg.DERPMap {
392+
return proxyOnlyDERPMap
381393
}
382394
api.AGPL.DERPMapper.Store(&newDERPMapper)
383395

0 commit comments

Comments
 (0)