@@ -367,17 +367,29 @@ func TestDERPEndToEnd(t *testing.T) {
367
367
return true
368
368
}, testutil .WaitLong , testutil .IntervalMedium )
369
369
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
378
381
}
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
381
393
}
382
394
api .AGPL .DERPMapper .Store (& newDERPMapper )
383
395
0 commit comments