chore(provider/utils): fix flaky test caused by new random shuffle

This commit is contained in:
Quentin McGaw
2026-05-12 01:28:11 +00:00
parent 3ca4b48887
commit fd12e5f9e7
+20 -18
View File
@@ -27,11 +27,12 @@ func Test_GetConnection(t *testing.T) {
defaults ConnectionDefaults defaults ConnectionDefaults
ipv6Supported bool ipv6Supported bool
randSource rand.Source randSource rand.Source
connection models.Connection connections []models.Connection
errMessage string errMessage string
}{ }{
"storage filter error": { "storage filter error": {
filterError: errors.New("test error"), filterError: errors.New("test error"),
connections: []models.Connection{{}},
errMessage: "filtering servers: test error", errMessage: "filtering servers: test error",
}, },
"server without IPs": { "server without IPs": {
@@ -46,6 +47,7 @@ func Test_GetConnection(t *testing.T) {
OpenVPNUDPPort: 1, OpenVPNUDPPort: 1,
WireguardPort: 1, WireguardPort: 1,
}, },
connections: []models.Connection{{}},
errMessage: "no connection to pick from", errMessage: "no connection to pick from",
}, },
"OpenVPN server with hostname": { "OpenVPN server with hostname": {
@@ -61,13 +63,13 @@ func Test_GetConnection(t *testing.T) {
WithDefaults(providers.Mullvad), WithDefaults(providers.Mullvad),
defaults: NewConnectionDefaults(443, 1194, 58820), defaults: NewConnectionDefaults(443, 1194, 58820),
randSource: rand.NewSource(0), randSource: rand.NewSource(0),
connection: models.Connection{ connections: []models.Connection{{
Type: vpn.OpenVPN, Type: vpn.OpenVPN,
IP: netip.AddrFrom4([4]byte{1, 1, 1, 1}), IP: netip.AddrFrom4([4]byte{1, 1, 1, 1}),
Protocol: constants.UDP, Protocol: constants.UDP,
Port: 1194, Port: 1194,
Hostname: "name", Hostname: "name",
}, }},
}, },
"OpenVPN server with x509": { "OpenVPN server with x509": {
filteredServers: []models.Server{ filteredServers: []models.Server{
@@ -83,13 +85,13 @@ func Test_GetConnection(t *testing.T) {
WithDefaults(providers.Mullvad), WithDefaults(providers.Mullvad),
defaults: NewConnectionDefaults(443, 1194, 58820), defaults: NewConnectionDefaults(443, 1194, 58820),
randSource: rand.NewSource(0), randSource: rand.NewSource(0),
connection: models.Connection{ connections: []models.Connection{{
Type: vpn.OpenVPN, Type: vpn.OpenVPN,
IP: netip.AddrFrom4([4]byte{1, 1, 1, 1}), IP: netip.AddrFrom4([4]byte{1, 1, 1, 1}),
Protocol: constants.UDP, Protocol: constants.UDP,
Port: 1194, Port: 1194,
Hostname: "x509", Hostname: "x509",
}, }},
}, },
"server with IPv4 and IPv6": { "server with IPv4 and IPv6": {
filteredServers: []models.Server{ filteredServers: []models.Server{
@@ -111,12 +113,12 @@ func Test_GetConnection(t *testing.T) {
WithDefaults(providers.Mullvad), WithDefaults(providers.Mullvad),
defaults: NewConnectionDefaults(443, 1194, 58820), defaults: NewConnectionDefaults(443, 1194, 58820),
randSource: rand.NewSource(0), randSource: rand.NewSource(0),
connection: models.Connection{ connections: []models.Connection{{
Type: vpn.OpenVPN, Type: vpn.OpenVPN,
IP: netip.AddrFrom4([4]byte{1, 1, 1, 1}), IP: netip.AddrFrom4([4]byte{1, 1, 1, 1}),
Protocol: constants.UDP, Protocol: constants.UDP,
Port: 1194, Port: 1194,
}, }},
}, },
"server with IPv4 and IPv6 and ipv6 supported": { "server with IPv4 and IPv6 and ipv6 supported": {
filteredServers: []models.Server{ filteredServers: []models.Server{
@@ -134,12 +136,12 @@ func Test_GetConnection(t *testing.T) {
defaults: NewConnectionDefaults(443, 1194, 58820), defaults: NewConnectionDefaults(443, 1194, 58820),
ipv6Supported: true, ipv6Supported: true,
randSource: rand.NewSource(0), randSource: rand.NewSource(0),
connection: models.Connection{ connections: []models.Connection{{
Type: vpn.OpenVPN, Type: vpn.OpenVPN,
IP: netip.IPv6Unspecified(), IP: netip.IPv6Unspecified(),
Protocol: constants.UDP, Protocol: constants.UDP,
Port: 1194, Port: 1194,
}, }},
}, },
"mixed servers": { "mixed servers": {
filteredServers: []models.Server{ filteredServers: []models.Server{
@@ -149,12 +151,6 @@ func Test_GetConnection(t *testing.T) {
IPs: []netip.Addr{netip.AddrFrom4([4]byte{1, 1, 1, 1})}, IPs: []netip.Addr{netip.AddrFrom4([4]byte{1, 1, 1, 1})},
OvpnX509: "ovpnx509", OvpnX509: "ovpnx509",
}, },
{
VPN: vpn.Wireguard,
UDP: true,
IPs: []netip.Addr{netip.AddrFrom4([4]byte{2, 2, 2, 2})},
OvpnX509: "ovpnx509",
},
{ {
VPN: vpn.OpenVPN, VPN: vpn.OpenVPN,
UDP: true, UDP: true,
@@ -169,13 +165,19 @@ func Test_GetConnection(t *testing.T) {
WithDefaults(providers.Mullvad), WithDefaults(providers.Mullvad),
defaults: NewConnectionDefaults(443, 1194, 58820), defaults: NewConnectionDefaults(443, 1194, 58820),
randSource: rand.NewSource(0), randSource: rand.NewSource(0),
connection: models.Connection{ connections: []models.Connection{{
Type: vpn.OpenVPN, Type: vpn.OpenVPN,
IP: netip.AddrFrom4([4]byte{1, 1, 1, 1}), IP: netip.AddrFrom4([4]byte{1, 1, 1, 1}),
Protocol: constants.UDP, Protocol: constants.UDP,
Port: 1194, Port: 1194,
Hostname: "ovpnx509", Hostname: "ovpnx509",
}, }, {
Type: vpn.OpenVPN,
IP: netip.AddrFrom4([4]byte{3, 3, 3, 3}),
Protocol: constants.UDP,
Port: 1194,
Hostname: "hostname",
}},
}, },
} }
@@ -194,7 +196,7 @@ func Test_GetConnection(t *testing.T) {
testCase.serverSelection, testCase.defaults, testCase.ipv6Supported, testCase.serverSelection, testCase.defaults, testCase.ipv6Supported,
connPicker) connPicker)
assert.Equal(t, testCase.connection, connection) assert.Contains(t, testCase.connections, connection)
if testCase.errMessage != "" { if testCase.errMessage != "" {
assert.EqualError(t, err, testCase.errMessage) assert.EqualError(t, err, testCase.errMessage)
} else { } else {