Skip to content

feat: Auto select workspace proxy based on lowest latency #7515

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 16 commits into from
May 22, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add extra test for unknown latencies
  • Loading branch information
Emyrk committed May 12, 2023
commit d1c9f3fa79bca20bbf42e157b55076b013a87d48
35 changes: 29 additions & 6 deletions site/src/contexts/ProxyContext.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ jest.mock("contexts/useProxyLatency", () => ({

let hardCodedLatencies: Record<string, ProxyLatency.ProxyLatencyReport> = {}

// fakeLatency is a helper function to make a Latency report from just a number.
const fakeLatency = (ms: number): ProxyLatency.ProxyLatencyReport => {
return {
latencyMS: ms,
Expand Down Expand Up @@ -164,12 +165,23 @@ const TestingScreen = () => {
}

interface ProxyContextSelectionTest {
// Regions is the list of regions to return via the "api" response.
regions: Region[]
// storageProxy should be the proxy stored in local storage before the
// component is mounted and context is loaded. This simulates opening a
// new window with a selection saved from before.
storageProxy: Region | undefined
// latencies is the hard coded latencies to return. If empty, no latencies
// are returned.
latencies?: Record<string, ProxyLatency.ProxyLatencyReport>
// afterLoad are actions to take after loading the component, but before
// assertions. This is useful for simulating user actions.
afterLoad?: (user: typeof userEvent) => Promise<void>

// Assert these values.
// expProxyID is the proxyID returned to be used.
expProxyID: string
// expUserProxyID is the user's stored selection.
expUserProxyID?: string
}

Expand Down Expand Up @@ -301,6 +313,23 @@ describe("ProxyContextSelection", () => {
},
},
],
[
// Excess proxies we do not have are low latency.
// This will probably never happen in production.
"unknown_regions_low_latency",
{
// Default to primary since we have unknowns
expProxyID: MockPrimaryWorkspaceProxy.id,
regions: MockWorkspaceProxies,
storageProxy: MockUnhealthyWildWorkspaceProxy,
expUserProxyID: MockUnhealthyWildWorkspaceProxy.id,
latencies: {
["some"]: fakeLatency(500),
["random"]: fakeLatency(100),
["ids"]: fakeLatency(25),
},
},
],
] as [string, ProxyContextSelectionTest][])(
`%s`,
async (
Expand All @@ -317,12 +346,6 @@ describe("ProxyContextSelection", () => {
// Mock the latencies
hardCodedLatencies = latencies

// jest.mock("contexts/useProxyLatency", () => ({
// useProxyLatency: () => {
// return latencies
// },
// }))

// Initial selection if present
if (storageProxy) {
saveUserSelectedProxy(storageProxy)
Expand Down