8000 chore(vpn): send ping results over tunnel by ethanndickson · Pull Request #18200 · coder/coder · GitHub
[go: up one dir, main page]

Skip to content

chore(vpn): send ping results over tunnel #18200

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Jun 6, 2025
Merged
Prev Previous commit
Next Next commit
review
  • Loading branch information
ethanndickson committed Jun 3, 2025
commit 176a375365de2a8b0735fc1bd64648cb26abbf10
35 changes: 35 additions & 0 deletions tailnet/derpmap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"testing"

"github.com/stretchr/testify/require"
"tailscale.com/ipn/ipnstate"
"tailscale.com/tailcfg"

"github.com/coder/coder/v2/tailnet"
Expand Down Expand Up @@ -236,3 +237,37 @@ func TestExtractDERPLatency(t *testing.T) {
require.Empty(t, latencyMs)
})
}

func TestExtractPreferredDERPName(t *testing.T) {
t.Parallel()
derpMap := &tailcfg.DERPMap{
Regions: map[int]*tailcfg.DERPRegion{
1: {RegionName: "New York"},
2: {RegionName: "London"},
},
}

t.Run("UsesPingRegion", func(t *testing.T) {
t.Parallel()
pingResult := &ipnstate.PingResult{DERPRegionID: 2}
node := &tailnet.Node{PreferredDERP: 1}
result := tailnet.ExtractPreferredDERPName(pingResult, node, derpMap)
require.Equal(t, "London", result)
})

t.Run("UsesNodePreferred", func(t *testing.T) {
t.Parallel()
pingResult := &ipnstate.PingResult{DERPRegionID: 0}
node := &tailnet.Node{PreferredDERP: 1}
result := tailnet.ExtractPreferredDERPName(pingResult, node, derpMap)
require.Equal(t, "New York", result)
})

t.Run("UnknownRegion", func(t *testing.T) {
t.Parallel()
pingResult := &ipnstate.PingResult{DERPRegionID: 99}
node := &tailnet.Node{PreferredDERP: 1}
result := tailnet.ExtractPreferredDERPName(pingResult, node, derpMap)
require.Equal(t, "Unnamed 99", result)
})
}
8 changes: 4 additions & 4 deletions vpn/tunnel_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ func TestTunnel_sendAgentUpdate(t *testing.T) {
}

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

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

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

func TestTunnel_sendAgentUpdateReconnect(t *testing.T) {
Expand Down
Loading
0