Skip to content

Commit f676731

Browse files
Emyrkpull[bot]
authored andcommitted
chore: If selecting an unhealthy proxy, default to primary (coder#7472)
* chore: If selecting an unhealthy proxy, default to primary
1 parent 8917ae8 commit f676731

File tree

3 files changed

+22
-11
lines changed

3 files changed

+22
-11
lines changed

site/src/contexts/ProxyContext.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {
22
MockPrimaryWorkspaceProxy,
33
MockWorkspaceProxies,
44
MockHealthyWildWorkspaceProxy,
5+
MockUnhealthyWildWorkspaceProxy,
56
} from "testHelpers/entities"
67
import { getPreferredProxy } from "./ProxyContext"
78

@@ -38,6 +39,14 @@ describe("ProxyContextGetURLs", () => {
3839
"",
3940
MockPrimaryWorkspaceProxy.wildcard_hostname,
4041
],
42+
// Primary is the default if the selected is unhealthy
43+
[
44+
"unhealthy selection",
45+
MockWorkspaceProxies,
46+
MockUnhealthyWildWorkspaceProxy,
47+
"",
48+
MockPrimaryWorkspaceProxy.wildcard_hostname,
49+
],
4150
// This should never happen, when there is no primary
4251
["no primary", [MockHealthyWildWorkspaceProxy], undefined, "", ""],
4352
])(

site/src/contexts/ProxyContext.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ export const getPreferredProxy = (
149149
(proxy) => selectedProxy && proxy.id === selectedProxy.id,
150150
)
151151

152-
if (!selectedProxy) {
153-
// If no proxy is selected, default to the primary proxy.
152+
// If no proxy is selected, or the selected proxy is unhealthy default to the primary proxy.
153+
if (!selectedProxy || !selectedProxy.healthy) {
154154
selectedProxy = proxies.find((proxy) => proxy.name === "primary")
155155
}
156156

site/src/testHelpers/entities.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,18 +88,20 @@ export const MockHealthyWildWorkspaceProxy: TypesGen.Region = {
8888
wildcard_hostname: "*.external.com",
8989
}
9090

91+
export const MockUnhealthyWildWorkspaceProxy: TypesGen.Region = {
92+
id: "8444931c-0247-4171-842a-569d9f9cbadb",
93+
name: "unhealthy",
94+
display_name: "Unhealthy",
95+
icon_url: "/emojis/1f92e.png",
96+
healthy: false,
97+
path_app_url: "https://unhealthy.coder.com",
98+
wildcard_hostname: "*unhealthy..coder.com",
99+
}
100+
91101
export const MockWorkspaceProxies: TypesGen.Region[] = [
92102
MockPrimaryWorkspaceProxy,
93103
MockHealthyWildWorkspaceProxy,
94-
{
95-
id: "8444931c-0247-4171-842a-569d9f9cbadb",
96-
name: "unhealthy",
97-
display_name: "Unhealthy",
98-
icon_url: "/emojis/1f92e.png",
99-
healthy: false,
100-
path_app_url: "https://unhealthy.coder.com",
101-
wildcard_hostname: "*unhealthy..coder.com",
102-
},
104+
MockUnhealthyWildWorkspaceProxy,
103105
{
104106
id: "26e84c16-db24-4636-a62d-aa1a4232b858",
105107
name: "nowildcard",

0 commit comments

Comments
 (0)