Skip to content

Commit 176a375

Browse files
committed
review
1 parent 896548d commit 176a375

File tree

2 files changed

+39
-4
lines changed

2 files changed

+39
-4
lines changed

tailnet/derpmap_test.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"testing"
1111

1212
"github.com/stretchr/testify/require"
13+
"tailscale.com/ipn/ipnstate"
1314
"tailscale.com/tailcfg"
1415

1516
"github.com/coder/coder/v2/tailnet"
@@ -236,3 +237,37 @@ func TestExtractDERPLatency(t *testing.T) {
236237
require.Empty(t, latencyMs)
237238
})
238239
}
240+
241+
func TestExtractPreferredDERPName(t *testing.T) {
242+
t.Parallel()
243+
derpMap := &tailcfg.DERPMap{
244+
Regions: map[int]*tailcfg.DERPRegion{
245+
1: {RegionName: "New York"},
246+
2: {RegionName: "London"},
247+
},
248+
}
249+
250+
t.Run("UsesPingRegion", func(t *testing.T) {
251+
t.Parallel()
252+
pingResult := &ipnstate.PingResult{DERPRegionID: 2}
253+
node := &tailnet.Node{PreferredDERP: 1}
254+
result := tailnet.ExtractPreferredDERPName(pingResult, node, derpMap)
255+
require.Equal(t, "London", result)
256+
})
257+
258+
t.Run("UsesNodePreferred", func(t *testing.T) {
259+
t.Parallel()
260+
pingResult := &ipnstate.PingResult{DERPRegionID: 0}
261+
node := &tailnet.Node{PreferredDERP: 1}
262+
result := tailnet.ExtractPreferredDERPName(pingResult, node, derpMap)
263+
require.Equal(t, "New York", result)
264+
})
265+
266+
t.Run("UnknownRegion", func(t *testing.T) {
267+
t.Parallel()
268+
pingResult := &ipnstate.PingResult{DERPRegionID: 99}
269+
node := &tailnet.Node{PreferredDERP: 1}
270+
result := tailnet.ExtractPreferredDERPName(pingResult, node, derpMap)
271+
require.Equal(t, "Unnamed 99", result)
272+
})
273+
}

vpn/tunnel_internal_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ func TestTunnel_sendAgentUpdate(t *testing.T) {
461461
}
462462

463463
// Latency is gathered in the background, so it'll eventually be sent
464-
require.Eventually(t, func() bool {
464+
testutil.Eventually(ctx, t, func(ctx context.Context) bool {
465465
mClock.AdvanceNext()
466466
req = testutil.TryReceive(ctx, t, mgr.requests)
467467
if len(req.msg.GetPeerUpdate().UpsertedAgents) == 0 {
@@ -474,7 +474,7 @@ func TestTunnel_sendAgentUpdate(t *testing.T) {
474474
return false
475475
}
476476
return req.msg.GetPeerUpdate().UpsertedAgents[0].LastPing.PreferredDerp == "Coder Region"
477-
}, testutil.WaitShort, testutil.IntervalFast)
477+
}, testutil.IntervalFast)
478478

479479
// Upsert a new agent
480480
err = tun.Update(tailnet.WorkspaceUpdate{
@@ -538,7 +538,7 @@ func TestTunnel_sendAgentUpdate(t *testing.T) {
538538
require.Equal(t, hsTime, req.msg.GetPeerUpdate().UpsertedAgents[0].LastHandshake.AsTime())
539539

540540
// Eventually the second agent's latency is set
541-
require.Eventually(t, func() bool {
541+
testutil.Eventually(ctx, t, func(ctx context.Context) bool {
542542
mClock.AdvanceNext()
543543
req = testutil.TryReceive(ctx, t, mgr.requests)
544544
if len(req.msg.GetPeerUpdate().UpsertedAgents) == 0 {
@@ -551,7 +551,7 @@ func TestTunnel_sendAgentUpdate(t *testing.T) {
551551
return false
552552
}
553553
return req.msg.GetPeerUpdate().UpsertedAgents[0].LastPing.PreferredDerp == "Coder Region"
554-
}, testutil.WaitShort, testutil.IntervalFast)
554+
}, testutil.IntervalFast)
555555
}
556556

557557
func TestTunnel_sendAgentUpdateReconnect(t *testing.T) {

0 commit comments

Comments
 (0)