Skip to content

Commit ee7828a

Browse files
authored
chore: fix wsproxy test flake (#12280)
* chore: fix wsproxy test flake * fixup! chore: fix wsproxy test flake
1 parent 4cc132c commit ee7828a

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

enterprise/wsproxy/wsproxy_test.go

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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)