- Notifications
You must be signed in to change notification settings - Fork927
test(site): add e2e tests for workspace proxies#13009
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
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
8 commits Select commitHold shift + click to select a range
5d08a67
WIP
mtojek6e86daf
Merge branch 'main' into 12508-proxy
mtojekb9285cb
e2e workspace proxy
mtojek614ae1f
WIP
mtojekfb8441a
fix
mtojekd78f99e
start proxy
mtojek6fdb908
comments
mtojek1af97d6
fix: logo
mtojekFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
1 change: 1 addition & 0 deletionssite/e2e/constants.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletionsite/e2e/helpers.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletionssite/e2e/proxy.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { spawn, type ChildProcess, exec } from "child_process"; | ||
import { coderMain, coderPort, workspaceProxyPort } from "./constants"; | ||
import { waitUntilUrlIsNotResponding } from "./helpers"; | ||
export const startWorkspaceProxy = async ( | ||
token: string, | ||
): Promise<ChildProcess> => { | ||
const cp = spawn("go", ["run", coderMain, "wsproxy", "server"], { | ||
env: { | ||
...process.env, | ||
CODER_PRIMARY_ACCESS_URL: `http://127.0.0.1:${coderPort}`, | ||
CODER_PROXY_SESSION_TOKEN: token, | ||
CODER_HTTP_ADDRESS: `localhost:${workspaceProxyPort}`, | ||
}, | ||
}); | ||
cp.stdout.on("data", (data: Buffer) => { | ||
// eslint-disable-next-line no-console -- Log wsproxy activity | ||
console.log( | ||
`[wsproxy] [stdout] [onData] ${data.toString().replace(/\n$/g, "")}`, | ||
); | ||
}); | ||
cp.stderr.on("data", (data: Buffer) => { | ||
// eslint-disable-next-line no-console -- Log wsproxy activity | ||
console.log( | ||
`[wsproxy] [stderr] [onData] ${data.toString().replace(/\n$/g, "")}`, | ||
); | ||
}); | ||
return cp; | ||
}; | ||
export const stopWorkspaceProxy = async ( | ||
cp: ChildProcess, | ||
goRun: boolean = true, | ||
) => { | ||
exec(goRun ? `pkill -P ${cp.pid}` : `kill ${cp.pid}`, (error) => { | ||
if (error) { | ||
throw new Error(`exec error: ${JSON.stringify(error)}`); | ||
} | ||
}); | ||
await waitUntilUrlIsNotResponding(`http://127.0.0.1:${workspaceProxyPort}`); | ||
}; |
2 changes: 1 addition & 1 deletionsite/e2e/tests/deployment/appearance.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletionssite/e2e/tests/deployment/workspaceProxies.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
import { test, expect, type Page } from "@playwright/test"; | ||
import { createWorkspaceProxy } from "api/api"; | ||
import { setupApiCalls } from "../../api"; | ||
import { coderPort, workspaceProxyPort } from "../../constants"; | ||
import { randomName, requiresEnterpriseLicense } from "../../helpers"; | ||
import { startWorkspaceProxy, stopWorkspaceProxy } from "../../proxy"; | ||
test("default proxy is online", async ({ page }) => { | ||
requiresEnterpriseLicense(); | ||
await setupApiCalls(page); | ||
await page.goto("/deployment/workspace-proxies", { | ||
waitUntil: "domcontentloaded", | ||
}); | ||
// Verify if the default proxy is healthy | ||
const workspaceProxyPrimary = page.locator( | ||
`table.MuiTable-root tr[data-testid="primary"]`, | ||
); | ||
const workspaceProxyName = workspaceProxyPrimary.locator("td.name span"); | ||
const workspaceProxyURL = workspaceProxyPrimary.locator("td.url"); | ||
const workspaceProxyStatus = workspaceProxyPrimary.locator("td.status span"); | ||
await expect(workspaceProxyName).toHaveText("Default"); | ||
await expect(workspaceProxyURL).toHaveText("http://localhost:" + coderPort); | ||
await expect(workspaceProxyStatus).toHaveText("Healthy"); | ||
}); | ||
test("custom proxy is online", async ({ page }) => { | ||
requiresEnterpriseLicense(); | ||
await setupApiCalls(page); | ||
const proxyName = randomName(); | ||
// Register workspace proxy | ||
const proxyResponse = await createWorkspaceProxy({ | ||
name: proxyName, | ||
display_name: "", | ||
icon: "/emojis/1f1e7-1f1f7.png", | ||
}); | ||
expect(proxyResponse.proxy_token).toBeDefined(); | ||
// Start "wsproxy server" | ||
const proxyServer = await startWorkspaceProxy(proxyResponse.proxy_token); | ||
await waitUntilWorkspaceProxyIsHealthy(page, proxyName); | ||
// Verify if custom proxy is healthy | ||
await page.goto("/deployment/workspace-proxies", { | ||
waitUntil: "domcontentloaded", | ||
}); | ||
const workspaceProxy = page.locator(`table.MuiTable-root tr`, { | ||
hasText: proxyName, | ||
}); | ||
const workspaceProxyName = workspaceProxy.locator("td.name span"); | ||
const workspaceProxyURL = workspaceProxy.locator("td.url"); | ||
const workspaceProxyStatus = workspaceProxy.locator("td.status span"); | ||
await expect(workspaceProxyName).toHaveText(proxyName); | ||
await expect(workspaceProxyURL).toHaveText( | ||
`http://127.0.0.1:${workspaceProxyPort}`, | ||
); | ||
await expect(workspaceProxyStatus).toHaveText("Healthy"); | ||
// Tear down the proxy | ||
await stopWorkspaceProxy(proxyServer); | ||
}); | ||
const waitUntilWorkspaceProxyIsHealthy = async ( | ||
page: Page, | ||
proxyName: string, | ||
) => { | ||
await page.goto("/deployment/workspace-proxies", { | ||
waitUntil: "domcontentloaded", | ||
}); | ||
const maxRetries = 30; | ||
const retryIntervalMs = 1000; | ||
let retries = 0; | ||
while (retries < maxRetries) { | ||
await page.reload(); | ||
const workspaceProxy = page.locator(`table.MuiTable-root tr`, { | ||
hasText: proxyName, | ||
}); | ||
const workspaceProxyStatus = workspaceProxy.locator("td.status span"); | ||
try { | ||
await expect(workspaceProxyStatus).toHaveText("Healthy", { | ||
timeout: 1_000, | ||
}); | ||
return; // healthy! | ||
} catch { | ||
retries++; | ||
await new Promise((resolve) => setTimeout(resolve, retryIntervalMs)); | ||
} | ||
} | ||
throw new Error( | ||
`Workspace proxy "${proxyName}" is unhealthy after ${ | ||
maxRetries * retryIntervalMs | ||
}ms`, | ||
); | ||
}; |
7 changes: 7 additions & 0 deletionssite/src/api/api.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletionssite/src/pages/LoginPage/LoginPageView.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
10 changes: 7 additions & 3 deletionssite/src/pages/UserSettingsPage/WorkspaceProxyPage/WorkspaceProxyRow.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.