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
Move arg inside the funcs
  • Loading branch information
Emyrk committed May 12, 2023
commit c739f245f36b5127bc2d3c4a876f1c73b2cc1d88
16 changes: 8 additions & 8 deletions site/src/contexts/ProxyContext.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { rest } from "msw"
import { Region } from "api/typesGenerated"
import "testHelpers/localstorage"
import userEvent from "@testing-library/user-event"
import UserEvent from "@testing-library/user-event"

// Mock useProxyLatency to use a hard-coded latency. 'jest.mock' must be called
// here and not inside a unit test.
Expand Down Expand Up @@ -176,7 +177,7 @@ interface ProxyContextSelectionTest {
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>
afterLoad?: () => Promise<void>

// Assert these values.
// expProxyID is the proxyID returned to be used.
Expand All @@ -192,15 +193,15 @@ describe("ProxyContextSelection", () => {
})

// A way to simulate a user clearing the proxy selection.
const clearProxyAction = async (user: typeof userEvent): Promise<void> => {
const clearProxyAction = async (): Promise<void> => {
const user = userEvent.setup()
const clearProxyButton = screen.getByTestId("clearProxy")
await user.click(clearProxyButton)
}

const userSelectProxy = (
proxy: Region,
): ((user: typeof userEvent) => Promise<void>) => {
return async (user): Promise<void> => {
const userSelectProxy = (proxy: Region): (() => Promise<void>) => {
return async (): Promise<void> => {
const user = userEvent.setup()
const selectData = screen.getByTestId("userSelectProxyData")
selectData.innerText = JSON.stringify(proxy)

Expand Down Expand Up @@ -366,9 +367,8 @@ describe("ProxyContextSelection", () => {
TestingComponent()
await waitForLoaderToBeRemoved()

const user = userEvent.setup()
if (afterLoad) {
await afterLoad(user)
await afterLoad()
}

await screen.findByTestId("isFetched").then((x) => {
Expand Down