Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Emyrk merged 16 commits intomainfromstevenmasley/proxy_latency_pick
May 22, 2023
Merged
Show file tree
Hide file tree
Changes from1 commit
Commits
Show all changes
16 commits
Select commitHold shift + click to select a range
159538c
WIP: Proxy auto select and user selection state
EmyrkMay 11, 2023
1305931
chore: Auto select based on latency
EmyrkMay 12, 2023
d1c9f3f
Add extra test for unknown latencies
EmyrkMay 12, 2023
c739f24
Move arg inside the funcs
EmyrkMay 12, 2023
ae26777
Fmt
EmyrkMay 12, 2023
523e492
Duplicate import
EmyrkMay 12, 2023
877c0c9
PR feedback
EmyrkMay 12, 2023
8d26643
Merge remote-tracking branch 'origin/main' into stevenmasley/proxy_la…
EmyrkMay 12, 2023
5c534fa
Refactor
EmyrkMay 12, 2023
a3703e1
Fix useEffect dep
EmyrkMay 18, 2023
c210e8d
Merge remote-tracking branch 'origin/main' into stevenmasley/proxy_la…
EmyrkMay 18, 2023
a358258
Fix deps comment
EmyrkMay 18, 2023
ec860c3
Remove comment
EmyrkMay 22, 2023
3197eb1
Merge remote-tracking branch 'origin/main' into stevenmasley/proxy_la…
EmyrkMay 22, 2023
ebb6a76
Mock the hook with a hook
EmyrkMay 22, 2023
549093e
Remove unused dep
EmyrkMay 22, 2023
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
NextNext commit
WIP: Proxy auto select and user selection state
Lotta comments
  • Loading branch information
@Emyrk
Emyrk committedMay 11, 2023
commit159538c3741b4952ba213692a3b429da07483305
3 changes: 3 additions & 0 deletionssite/src/components/AppLink/AppLink.stories.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -26,6 +26,9 @@ const Template: Story<AppLinkProps> = (args) => (
setProxy: () => {
return
},
clearProxy: () => {
return
},
}}
>
<AppLink {...args} />
Expand Down
3 changes: 3 additions & 0 deletionssite/src/components/Resources/AgentRow.stories.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -65,6 +65,9 @@ const TemplateFC = (
setProxy: () => {
return
},
clearProxy: () => {
return
},
}}
>
<AgentRow {...args} />
Expand Down
6 changes: 6 additions & 0 deletionssite/src/components/Resources/ResourceCard.stories.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -30,6 +30,9 @@ Example.args = {
setProxy: () => {
return
},
clearProxy: () => {
return
},
}}
>
<AgentRow
Expand DownExpand Up@@ -97,6 +100,9 @@ BunchOfMetadata.args = {
setProxy: () => {
return
},
clearProxy: () => {
return
},
}}
>
<AgentRow
Expand Down
3 changes: 3 additions & 0 deletionssite/src/components/Workspace/Workspace.stories.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -35,6 +35,9 @@ const Template: Story<WorkspaceProps> = (args) => (
setProxy: () => {
return
},
clearProxy: () => {
return
},
}}
>
<Workspace {...args} />
Expand Down
62 changes: 0 additions & 62 deletionssite/src/contexts/ProxyContext.test.ts
View file
Open in desktop

This file was deleted.

192 changes: 192 additions & 0 deletionssite/src/contexts/ProxyContext.test.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
import {
MockPrimaryWorkspaceProxy,
MockWorkspaceProxies,
MockHealthyWildWorkspaceProxy,
MockUnhealthyWildWorkspaceProxy,
} from "testHelpers/entities"
import {
getPreferredProxy,
ProxyProvider,
saveUserSelectedProxy,
useProxy,
} from "./ProxyContext"
import * as ProxyContextModule from "./ProxyContext"
import {
renderWithAuth,
waitForLoaderToBeRemoved,
} from "testHelpers/renderHelpers"
import { screen } from "@testing-library/react"
import { server } from "testHelpers/server"
import "testHelpers/localstorage"
import { rest } from "msw"
import { Region } from "api/typesGenerated"

describe("ProxyContextGetURLs", () => {
it.each([
["empty", [], undefined, "", ""],
// Primary has no path app URL. Uses relative links
[
"primary",
[MockPrimaryWorkspaceProxy],
MockPrimaryWorkspaceProxy,
"",
MockPrimaryWorkspaceProxy.wildcard_hostname,
],
[
"regions selected",
MockWorkspaceProxies,
MockHealthyWildWorkspaceProxy,
MockHealthyWildWorkspaceProxy.path_app_url,
MockHealthyWildWorkspaceProxy.wildcard_hostname,
],
// Primary is the default if none selected
[
"no selected",
[MockPrimaryWorkspaceProxy],
undefined,
"",
MockPrimaryWorkspaceProxy.wildcard_hostname,
],
[
"regions no select primary default",
MockWorkspaceProxies,
undefined,
"",
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, "", ""],
])(
`%p`,
(_, regions, selected, preferredPathAppURL, preferredWildcardHostname) => {
const preferred = getPreferredProxy(regions, selected)
expect(preferred.preferredPathAppURL).toBe(preferredPathAppURL)
expect(preferred.preferredWildcardHostname).toBe(
preferredWildcardHostname,
)
},
)
})

// interface ProxySelectTest {
// name: string
// actions: ()
// }

const TestingComponent = () => {
return renderWithAuth(
<ProxyProvider>
<TestingScreen />
</ProxyProvider>,
{
route: `/proxies`,
path: "/proxies",
},
)
}

// TestingScreen just mounts some components that we can check in the unit test.
const TestingScreen = () => {
const { proxy, isFetched, isLoading } = useProxy()
return (
<>
<div data-testid="isFetched" title={isFetched.toString()}></div>
<div data-testid="isLoading" title={isLoading.toString()}></div>
<div
data-testid="preferredProxy"
title={proxy.selectedProxy && proxy.selectedProxy.id}
></div>
</>
)
}

interface ProxyContextSelectionTest {
expSelectedProxyID: string
regions: Region[]
storageProxy: Region | undefined
}

describe("ProxyContextSelection", () => {
beforeEach(() => {
window.localStorage.clear()
})

it.each([
[
"empty",
{
expSelectedProxyID: "",
regions: [],
storageProxy: undefined,
},
],
[
"regions_no_selection",
{
expSelectedProxyID: MockPrimaryWorkspaceProxy.id,
regions: MockWorkspaceProxies,
storageProxy: undefined,
},
],
[
"regions_selected_unhealthy",
{
expSelectedProxyID: MockPrimaryWorkspaceProxy.id,
regions: MockWorkspaceProxies,
storageProxy: MockUnhealthyWildWorkspaceProxy,
},
],
] as [string, ProxyContextSelectionTest][])(
`%s`,
async (_, { expSelectedProxyID, regions, storageProxy }) => {
// Initial selection if present
if (storageProxy) {
saveUserSelectedProxy(storageProxy)
}

// Mock the API response
server.use(
rest.get("/api/v2/regions", async (req, res, ctx) => {
return res(
ctx.status(200),
ctx.json({
regions: regions,
}),
)
}),
)

TestingComponent()
await waitForLoaderToBeRemoved()

await screen.findByTestId("isFetched").then((x) => {
expect(x.title).toBe("true")
})
await screen.findByTestId("isLoading").then((x) => {
expect(x.title).toBe("false")
})
await screen.findByTestId("preferredProxy").then((x) => {
expect(x.title).toBe(expSelectedProxyID)
})

// const { proxy, proxies, isFetched, isLoading, proxyLatencies } = useProxy()
// expect(isLoading).toBe(false)
// expect(isFetched).toBe(true)

// expect(x).toBe(2)
// const preferred = getPreferredProxy(regions, selected)
// expect(preferred.preferredPathAppURL).toBe(preferredPathAppURL)
// expect(preferred.preferredWildcardHostname).toBe(
// preferredWildcardHostname,
// )
},
)
})
Loading

[8]ページ先頭

©2009-2025 Movatter.jp