chore: If selecting an unhealthy proxy, default to primary (#7472)

* chore: If selecting an unhealthy proxy, default to primary
This commit is contained in:
Steven Masley 2023-05-10 13:10:06 -05:00 committed by GitHub
parent 3f9af6f5e7
commit fb86ac2608
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 11 deletions

View File

@ -2,6 +2,7 @@ import {
MockPrimaryWorkspaceProxy,
MockWorkspaceProxies,
MockHealthyWildWorkspaceProxy,
MockUnhealthyWildWorkspaceProxy,
} from "testHelpers/entities"
import { getPreferredProxy } from "./ProxyContext"
@ -38,6 +39,14 @@ describe("ProxyContextGetURLs", () => {
"",
MockPrimaryWorkspaceProxy.wildcard_hostname,
],
// Primary is the default if the selected is unhealthy
[
"unhealthy selection",
MockWorkspaceProxies,
MockUnhealthyWildWorkspaceProxy,
"",
MockPrimaryWorkspaceProxy.wildcard_hostname,
],
// This should never happen, when there is no primary
["no primary", [MockHealthyWildWorkspaceProxy], undefined, "", ""],
])(

View File

@ -149,8 +149,8 @@ export const getPreferredProxy = (
(proxy) => selectedProxy && proxy.id === selectedProxy.id,
)
if (!selectedProxy) {
// If no proxy is selected, default to the primary proxy.
// If no proxy is selected, or the selected proxy is unhealthy default to the primary proxy.
if (!selectedProxy || !selectedProxy.healthy) {
selectedProxy = proxies.find((proxy) => proxy.name === "primary")
}

View File

@ -88,18 +88,20 @@ export const MockHealthyWildWorkspaceProxy: TypesGen.Region = {
wildcard_hostname: "*.external.com",
}
export const MockUnhealthyWildWorkspaceProxy: TypesGen.Region = {
id: "8444931c-0247-4171-842a-569d9f9cbadb",
name: "unhealthy",
display_name: "Unhealthy",
icon_url: "/emojis/1f92e.png",
healthy: false,
path_app_url: "https://unhealthy.coder.com",
wildcard_hostname: "*unhealthy..coder.com",
}
export const MockWorkspaceProxies: TypesGen.Region[] = [
MockPrimaryWorkspaceProxy,
MockHealthyWildWorkspaceProxy,
{
id: "8444931c-0247-4171-842a-569d9f9cbadb",
name: "unhealthy",
display_name: "Unhealthy",
icon_url: "/emojis/1f92e.png",
healthy: false,
path_app_url: "https://unhealthy.coder.com",
wildcard_hostname: "*unhealthy..coder.com",
},
MockUnhealthyWildWorkspaceProxy,
{
id: "26e84c16-db24-4636-a62d-aa1a4232b858",
name: "nowildcard",