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

fix: use pre-built binary instead ofgo run in e2e tests#16236

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
aslilac merged 5 commits intomainfromlilac/e2e-skip-app
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes fromall commits
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
3 changes: 3 additions & 0 deletions.github/workflows/ci.yaml
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -704,6 +704,9 @@ jobs:
- run: make gen/mark-fresh
name: make gen

- run: make site/e2e/bin/coder
name: make coder

- run: pnpm build
env:
NODE_OPTIONS: ${{ github.repository_owner == 'coder' && '--max_old_space_size=8192' || '' }}
Expand Down
1 change: 1 addition & 0 deletions.gitignore
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -36,6 +36,7 @@ site/.swc
.gen-golden

# Build
bin/
build/
dist/
out/
Expand Down
7 changes: 6 additions & 1 deletionMakefile
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -944,7 +944,12 @@ test-clean:
go clean -testcache
.PHONY: test-clean

test-e2e: site/node_modules/.installed site/out/index.html
site/e2e/bin/coder: go.mod go.sum $(GO_SRC_FILES)
go build -o $@ \
-tags ts_omit_aws,ts_omit_bird,ts_omit_tap,ts_omit_kube \
./enterprise/cmd/coder

test-e2e: site/e2e/bin/coder site/node_modules/.installed site/out/index.html
cd site/
ifdef CI
DEBUG=pw:api pnpm playwright:test --forbid-only --workers 1
Expand Down
2 changes: 1 addition & 1 deletionsite/e2e/constants.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
import * as path from "node:path";

export constcoderMain = path.join(__dirname, "../../enterprise/cmd/coder");
export constcoderBinary = path.join(__dirname, "./bin/coder");

// Default port from the server
export const coderPort = process.env.CODER_E2E_PORT
Expand Down
31 changes: 10 additions & 21 deletionssite/e2e/helpers.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,7 +15,7 @@ import * as ssh from "ssh2";
import { TarWriter } from "utils/tar";
import {
agentPProfPort,
coderMain,
coderBinary,
coderPort,
defaultOrganizationName,
defaultPassword,
Expand DownExpand Up@@ -311,12 +311,9 @@ export const createGroup = async (page: Page): Promise<string> => {
export const sshIntoWorkspace = async (
page: Page,
workspace: string,
binaryPath ="go",
binaryPath =coderBinary,
binaryArgs: string[] = [],
): Promise<ssh.Client> => {
if (binaryPath === "go") {
binaryArgs = ["run", coderMain];
}
const sessionToken = await findSessionToken(page);
return new Promise<ssh.Client>((resolve, reject) => {
const cp = spawn(binaryPath, [...binaryArgs, "ssh", "--stdio", workspace], {
Expand DownExpand Up@@ -398,7 +395,7 @@ export const startAgent = async (
page: Page,
token: string,
): Promise<ChildProcess> => {
return startAgentWithCommand(page, token,"go", "run", coderMain);
return startAgentWithCommand(page, token,coderBinary);
};

/**
Expand DownExpand Up@@ -479,27 +476,21 @@ export const startAgentWithCommand = async (
},
});
cp.stdout.on("data", (data: Buffer) => {
console.info(
`[agent] [stdout] [onData] ${data.toString().replace(/\n$/g, "")}`,
);
console.info(`[agent][stdout] ${data.toString().replace(/\n$/g, "")}`);
});
cp.stderr.on("data", (data: Buffer) => {
console.info(
`[agent] [stderr] [onData] ${data.toString().replace(/\n$/g, "")}`,
);
console.info(`[agent][stderr] ${data.toString().replace(/\n$/g, "")}`);
});

await page
.getByTestId("agent-status-ready")
.waitFor({ state: "visible", timeout:45_000 });
.waitFor({ state: "visible", timeout:15_000 });
return cp;
};

export const stopAgent = async (cp: ChildProcess, goRun = true) => {
// When the web server is started with `go run`, it spawns a child process with coder server.
// `pkill -P` terminates child processes belonging the same group as `go run`.
// The command `kill` is used to terminate a web server started as a standalone binary.
exec(goRun ? `pkill -P ${cp.pid}` : `kill ${cp.pid}`, (error) => {
export const stopAgent = async (cp: ChildProcess) => {
// The command `kill` is used to terminate an agent started as a standalone binary.
exec(`kill ${cp.pid}`, (error) => {
if (error) {
throw new Error(`exec error: ${JSON.stringify(error)}`);
}
Expand DownExpand Up@@ -922,10 +913,8 @@ export const updateTemplate = async (

const sessionToken = await findSessionToken(page);
const child = spawn(
"go",
coderBinary,
[
"run",
coderMain,
"templates",
"push",
"--test.provisioner",
Expand Down
40 changes: 3 additions & 37 deletionssite/e2e/playwright.config.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
import { execSync } from "node:child_process";
import * as path from "node:path";
import { defineConfig } from "@playwright/test";
import {
coderMain,
coderPort,
coderdPProfPort,
e2eFakeExperiment1,
Expand All@@ -13,45 +11,12 @@ import {

export const wsEndpoint = process.env.CODER_E2E_WS_ENDPOINT;

// If running terraform tests, verify the requirements exist in the
// environment.
//
// These execs will throw an error if the status code is non-zero.
// So if both these work, then we can launch terraform provisioners.
let hasTerraform = false;
let hasDocker = false;
try {
execSync("terraform --version");
hasTerraform = true;
} catch {
/* empty */
}

try {
execSync("docker --version");
hasDocker = true;
} catch {
/* empty */
}

if (!hasTerraform || !hasDocker) {
const msg = `Terraform provisioners require docker & terraform binaries to function. \n${
hasTerraform
? ""
: "\tThe `terraform` executable is not present in the runtime environment.\n"
}${
hasDocker
? ""
: "\tThe `docker` executable is not present in the runtime environment.\n"
}`;
throw new Error(msg);
}

const localURL = (port: number, path: string): string => {
return `http://localhost:${port}${path}`;
};

export default defineConfig({
globalSetup: require.resolve("./setup/preflight"),
projects: [
{
name: "testsSetup",
Expand DownExpand Up@@ -84,7 +49,8 @@ export default defineConfig({
webServer: {
url: `http://localhost:${coderPort}/api/v2/deployment/config`,
command: [
`go run -tags embed ${coderMain} server`,
`go run -tags embed ${path.join(__dirname, "../../enterprise/cmd/coder")}`,
"server",
"--global-config $(mktemp -d -t e2e-XXXXXXXXXX)",
`--access-url=http://localhost:${coderPort}`,
`--http-address=0.0.0.0:${coderPort}`,
Expand Down
8 changes: 4 additions & 4 deletionssite/e2e/proxy.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
import { type ChildProcess, exec, spawn } from "node:child_process";
import {coderMain, coderPort, workspaceProxyPort } from "./constants";
import {coderBinary, coderPort, workspaceProxyPort } from "./constants";
import { waitUntilUrlIsNotResponding } from "./helpers";

export const startWorkspaceProxy = async (
token: string,
): Promise<ChildProcess> => {
const cp = spawn("go", ["run", coderMain,"wsproxy", "server"], {
const cp = spawn(coderBinary, ["wsproxy", "server"], {
env: {
...process.env,
CODER_PRIMARY_ACCESS_URL: `http://127.0.0.1:${coderPort}`,
Expand All@@ -26,8 +26,8 @@ export const startWorkspaceProxy = async (
return cp;
};

export const stopWorkspaceProxy = async (cp: ChildProcess, goRun = true) => {
exec(goRun ? `pkill -P ${cp.pid}` :`kill ${cp.pid}`, (error) => {
export const stopWorkspaceProxy = async (cp: ChildProcess) => {
exec(`kill ${cp.pid}`, (error) => {
if (error) {
throw new Error(`exec error: ${JSON.stringify(error)}`);
}
Expand Down
45 changes: 45 additions & 0 deletionssite/e2e/setup/preflight.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
import { execSync } from "node:child_process";
import * as path from "node:path";

export default function () {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Is there a reason why this is a default function instead of a named one? Not sure if our setup is looking for default exports specifically

Copy link
MemberAuthor

@aslilacaslilacJan 23, 2025
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

yeah, if you look in playwright.config.ts we specify aglobalSetup option with a path to this file as the value. playwright will then load this file and execute the default export exactly once per test run.

it's not safe to do any of this in the playwright.config.ts file directly because that gets executed once per worker (ie. potentially dozens of times per run)

// If running terraform tests, verify the requirements exist in the
// environment.
//
// These execs will throw an error if the status code is non-zero.
// So if both these work, then we can launch terraform provisioners.
let hasTerraform = false;
let hasDocker = false;
try {
execSync("terraform --version");
hasTerraform = true;
} catch {
/* empty */
}

try {
execSync("docker --version");
hasDocker = true;
} catch {
/* empty */
}

if (!hasTerraform || !hasDocker) {
const msg = `Terraform provisioners require docker & terraform binaries to function. \n${
hasTerraform
? ""
: "\tThe `terraform` executable is not present in the runtime environment.\n"
}${
hasDocker
? ""
: "\tThe `docker` executable is not present in the runtime environment.\n"
}`;
throw new Error(msg);
}

if (!process.env.CI) {
console.info("==> make site/e2e/bin/coder");
execSync("make site/e2e/bin/coder", {
cwd: path.join(__dirname, "../../../"),
});
}
}
4 changes: 1 addition & 3 deletionssite/e2e/tests/app.spec.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -18,8 +18,6 @@ test.beforeEach(async ({ page }) => {
});

test("app", async ({ context, page }) => {
test.setTimeout(75_000);

const appContent = "Hello World";
const token = randomUUID();
const srv = http
Expand DownExpand Up@@ -64,7 +62,7 @@ test("app", async ({ context, page }) => {

// Wait for the web terminal to open in a new tab
const pagePromise = context.waitForEvent("page");
await page.getByText(appName).click({ timeout:60_000 });
await page.getByText(appName).click({ timeout:10_000 });
const app = await pagePromise;
await app.waitForLoadState("domcontentloaded");
await app.getByText(appContent).isVisible();
Expand Down
2 changes: 1 addition & 1 deletionsite/e2e/tests/outdatedAgent.spec.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -64,5 +64,5 @@ test(`ssh with agent ${agentVersion}`, async ({ page }) => {
});

await stopWorkspace(page, workspaceName);
await stopAgent(agent, false);
await stopAgent(agent);
});
2 changes: 0 additions & 2 deletionssite/e2e/tests/outdatedCLI.spec.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -21,8 +21,6 @@ test.beforeEach(async ({ page }) => {
});

test(`ssh with client ${clientVersion}`, async ({ page }) => {
test.setTimeout(60_000);

const token = randomUUID();
const template = await createTemplate(page, {
apply: [
Expand Down
2 changes: 0 additions & 2 deletionssite/e2e/tests/webTerminal.spec.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -16,8 +16,6 @@ test.beforeEach(async ({ page }) => {
});

test("web terminal", async ({ context, page }) => {
test.setTimeout(75_000);

const token = randomUUID();
const template = await createTemplate(page, {
apply: [
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp