Skip to content

Commit

Permalink
Merge pull request #89 from zamm-dev/fix/vitest-segfault
Browse files Browse the repository at this point in the history
Fix exit code 139 segmentation fault after Vitest passes
  • Loading branch information
amosjyng authored May 20, 2024
2 parents 06bdcc6 + 8fc5466 commit 60f9aec
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 31 deletions.
14 changes: 8 additions & 6 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
name: Build entire program
runs-on: ubuntu-latest
container:
image: "ghcr.io/amosjyng/zamm:v0.1.1-build"
image: "ghcr.io/zamm-dev/zamm:v0.1.4-build"
options: --user root
env:
HOME: /root
Expand Down Expand Up @@ -150,6 +150,9 @@ jobs:
svelte:
name: Run Svelte tests
runs-on: ubuntu-latest
container:
image: "ghcr.io/zamm-dev/zamm:v0.1.4-build"
options: --user root
env:
PLAYWRIGHT_TIMEOUT: 60000
needs: build
Expand All @@ -176,14 +179,13 @@ jobs:
run: |
yarn install --frozen-lockfile
cd src-svelte && yarn install --frozen-lockfile && yarn svelte-kit sync
cd ../webdriver && yarn install --frozen-lockfile
# end of common dependency setup with downloaded artifacts
- name: Install remaining dependencies
- name: Copy over playwright binaries
run: |
yarn playwright install --with-deps
sudo apt-get install -y imagemagick
mkdir -p /github/home/.cache/
cp -R /root/.cache/ms-playwright /github/home/.cache/ms-playwright
- name: Run Svelte Tests
run: xvfb-run yarn workspace gui test
run: yarn workspace gui test
- name: Do better diff
if: always()
run: python3 diff-screenshots.py
Expand Down
6 changes: 5 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
FROM ubuntu:20.04
LABEL org.opencontainers.image.source="https://github.com/amosjyng/zamm"
LABEL org.opencontainers.image.source="https://github.com/zamm-dev/zamm"

ENV DEBIAN_FRONTEND=noninteractive
RUN apt update && \
Expand Down Expand Up @@ -44,3 +44,7 @@ RUN git clone --depth 1 --branch zamm/v0.0.0 https://github.com/amosjyng/async-o
echo "// dummy file" > src/lib.rs && \
echo "pub use tauri_build; fn main () {}" > build.rs && \
cargo build --release --features custom-protocol

# dev dependencies
RUN yarn playwright install --with-deps && \
apt install -y imagemagick
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.PHONY: rust-format rust-lint quicktype

BUILD_IMAGE = ghcr.io/amosjyng/zamm:v0.1.1-build
BUILD_IMAGE = ghcr.io/zamm-dev/zamm:v0.1.4-build
CURRENT_DIR = $(shell pwd)

build: svelte rust
Expand Down
3 changes: 3 additions & 0 deletions src-svelte/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ update-local-screenshots:
cp -r screenshots/local/testing/actual/* screenshots/local/baseline/
cp -r screenshots/local/testing/actual/* screenshots/baseline/

quick-test:
yarn vitest --pool=forks --exclude src/routes/storybook.test.ts run

test:
yarn test
python3 diff-screenshots.py
Expand Down
2 changes: 1 addition & 1 deletion src-svelte/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"build": "vite build",
"preview": "vite preview",
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
"test": "vitest run",
"test": "vitest --pool=forks run",
"test-watch": "vitest",
"storybook": "storybook dev -p 6006",
"build-storybook": "storybook build"
Expand Down
12 changes: 7 additions & 5 deletions src-svelte/src/lib/Slider.playwright.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
type Locator,
} from "@playwright/test";
import { afterAll, beforeAll, describe, test } from "vitest";
import { PLAYWRIGHT_TIMEOUT, PLAYWRIGHT_TEST_TIMEOUT } from "$lib/test-helpers";

const DEBUG_LOGGING = false;

Expand All @@ -21,6 +22,7 @@ describe("Slider drag test", () => {
beforeAll(async () => {
browser = await chromium.launch({ headless: true });
context = await browser.newContext();
context.setDefaultTimeout(PLAYWRIGHT_TIMEOUT);
await context.exposeFunction(
"_testRecordSoundPlayed",
() => numSoundsPlayed++,
Expand Down Expand Up @@ -88,7 +90,7 @@ describe("Slider drag test", () => {
});
await expectAriaValue(slider, 10);
},
{ retry: 2 },
{ retry: 2, timeout: PLAYWRIGHT_TEST_TIMEOUT },
);

test(
Expand All @@ -102,7 +104,7 @@ describe("Slider drag test", () => {
});
await expectAriaValue(slider, 0);
},
{ retry: 2 },
{ retry: 2, timeout: PLAYWRIGHT_TEST_TIMEOUT },
);

test(
Expand All @@ -124,7 +126,7 @@ describe("Slider drag test", () => {
expect(value).toBeGreaterThan(5);
expect(value).toBeLessThan(10);
},
{ retry: 2 },
{ retry: 2, timeout: PLAYWRIGHT_TEST_TIMEOUT },
);

test(
Expand All @@ -136,7 +138,7 @@ describe("Slider drag test", () => {
await slider.press("ArrowRight");
await expectAriaValue(slider, 6);
},
{ retry: 2 },
{ retry: 2, timeout: PLAYWRIGHT_TEST_TIMEOUT },
);

test(
Expand All @@ -156,6 +158,6 @@ describe("Slider drag test", () => {
expect(value).toBeLessThan(5);
expect(value).toBeGreaterThan(0);
},
{ retry: 2 },
{ retry: 2, timeout: PLAYWRIGHT_TEST_TIMEOUT },
);
});
12 changes: 7 additions & 5 deletions src-svelte/src/lib/Switch.playwright.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
type Locator,
} from "@playwright/test";
import { afterAll, beforeAll, describe, test } from "vitest";
import { PLAYWRIGHT_TIMEOUT, PLAYWRIGHT_TEST_TIMEOUT } from "$lib/test-helpers";

const DEBUG_LOGGING = false;

Expand All @@ -22,6 +23,7 @@ describe("Switch drag test", () => {
beforeAll(async () => {
browser = await chromium.launch({ headless: true });
context = await browser.newContext();
context.setDefaultTimeout(PLAYWRIGHT_TIMEOUT);
await context.exposeFunction(
"_testRecordSoundPlayed",
() => numSoundsPlayed++,
Expand Down Expand Up @@ -90,7 +92,7 @@ describe("Switch drag test", () => {
await expectAriaValue(onOffSwitch, true);
expect(numSoundsPlayed).toEqual(1);
},
{ retry: 2 },
{ retry: 2, timeout: PLAYWRIGHT_TEST_TIMEOUT },
);

test(
Expand All @@ -113,7 +115,7 @@ describe("Switch drag test", () => {
JSON.stringify(soundDelays) === JSON.stringify(expectedDelays),
).toBeTruthy();
},
{ retry: 2 },
{ retry: 2, timeout: PLAYWRIGHT_TEST_TIMEOUT },
);

test(
Expand Down Expand Up @@ -141,7 +143,7 @@ describe("Switch drag test", () => {
JSON.stringify(soundDelays) === JSON.stringify(expectedDelays),
).toBeTruthy();
},
{ retry: 2 },
{ retry: 2, timeout: PLAYWRIGHT_TEST_TIMEOUT },
);

test(
Expand All @@ -160,7 +162,7 @@ describe("Switch drag test", () => {
await expectAriaValue(onOffSwitch, false);
expect(numSoundsPlayed).toEqual(0);
},
{ retry: 2 },
{ retry: 2, timeout: PLAYWRIGHT_TEST_TIMEOUT },
);

test(
Expand Down Expand Up @@ -194,6 +196,6 @@ describe("Switch drag test", () => {
JSON.stringify(soundDelays) === JSON.stringify(expectedDelays),
).toBeTruthy();
},
{ retry: 2 },
{ retry: 2, timeout: PLAYWRIGHT_TEST_TIMEOUT },
);
});
14 changes: 12 additions & 2 deletions src-svelte/src/lib/test-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@ import { spawn, ChildProcess } from "child_process";
import fetch from "node-fetch";
import { tick } from "svelte";

export const PLAYWRIGHT_TIMEOUT =
process.env.PLAYWRIGHT_TIMEOUT === undefined
? 9_000
: parseInt(process.env.PLAYWRIGHT_TIMEOUT);
export const PLAYWRIGHT_TEST_TIMEOUT = 2.2 * PLAYWRIGHT_TIMEOUT;

async function startStorybook(): Promise<ChildProcess> {
return new Promise((resolve) => {
return new Promise((resolve, reject) => {
const storybookProcess = spawn("yarn", ["storybook", "--ci"]);
if (!storybookProcess) {
throw new Error("Could not start storybook process");
Expand All @@ -17,7 +23,11 @@ async function startStorybook(): Promise<ChildProcess> {
storybookProcess.stdout.on("data", (data) => {
const strippedData = data.toString().replace(/\\x1B\[\d+m/g, "");
if (storybookStartupMessage.test(strippedData)) {
resolve(storybookProcess);
fetch("http://localhost:6006")
.then(() => {
resolve(storybookProcess);
})
.catch(reject);
}
});

Expand Down
4 changes: 3 additions & 1 deletion src-svelte/src/routes/api-calls/ApiCalls.playwright.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
type Locator,
} from "@playwright/test";
import { afterAll, beforeAll, describe, test } from "vitest";
import { PLAYWRIGHT_TIMEOUT, PLAYWRIGHT_TEST_TIMEOUT } from "$lib/test-helpers";

const DEBUG_LOGGING = false;

Expand All @@ -20,6 +21,7 @@ describe("Api Calls endless scroll test", () => {
beforeAll(async () => {
browser = await chromium.launch({ headless: true });
context = await browser.newContext();
context.setDefaultTimeout(PLAYWRIGHT_TIMEOUT);
page = await context.newPage();

if (DEBUG_LOGGING) {
Expand Down Expand Up @@ -71,6 +73,6 @@ describe("Api Calls endless scroll test", () => {
});
await expectLastMessage(apiCallsScrollElement, "Mocking number 0.");
},
{ retry: 2 },
{ retry: 2, timeout: PLAYWRIGHT_TEST_TIMEOUT },
);
});
12 changes: 4 additions & 8 deletions src-svelte/src/routes/storybook.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@ import {
} from "jest-image-snapshot";
import * as fs from "fs/promises";
import sizeOf from "image-size";

const DEFAULT_TIMEOUT =
process.env.PLAYWRIGHT_TIMEOUT === undefined
? 9_000
: parseInt(process.env.PLAYWRIGHT_TIMEOUT);
import { PLAYWRIGHT_TIMEOUT, PLAYWRIGHT_TEST_TIMEOUT } from "$lib/test-helpers";

const SCREENSHOTS_BASE_DIR =
process.env.SCREENSHOTS_BASE_DIR === undefined
Expand Down Expand Up @@ -240,11 +236,11 @@ describe.concurrent("Storybook visual tests", () => {
beforeAll(async () => {
webkitBrowser = await webkit.launch({ headless: true });
webkitBrowserContext = await webkitBrowser.newContext();
webkitBrowserContext.setDefaultTimeout(DEFAULT_TIMEOUT);
webkitBrowserContext.setDefaultTimeout(PLAYWRIGHT_TIMEOUT);

chromiumBrowser = await chromium.launch({ headless: true });
chromiumBrowserContext = await chromiumBrowser.newContext();
chromiumBrowserContext.setDefaultTimeout(DEFAULT_TIMEOUT);
chromiumBrowserContext.setDefaultTimeout(PLAYWRIGHT_TIMEOUT);

console.log(
`Running tests with Webkit v${webkitBrowser.version()} and ` +
Expand Down Expand Up @@ -450,7 +446,7 @@ describe.concurrent("Storybook visual tests", () => {
},
{
retry: 1,
timeout: DEFAULT_TIMEOUT * 2.2,
timeout: PLAYWRIGHT_TEST_TIMEOUT,
},
);
}
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.1.4"
description = "Yet another AI chat app"
authors = ["Amos Ng <me@amos.ng>"]
license = "GPL-2.0-or-later"
repository = "https://github.com/amosjyng/zamm"
repository = "https://github.com/zamm-dev/zamm"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down

0 comments on commit 60f9aec

Please sign in to comment.