-
Notifications
You must be signed in to change notification settings - Fork 4
ENG-681 Automate database testing #957
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
base: main
Are you sure you want to change the base?
Changes from all commits
c270f6b
5b2a911
2ae0701
031640a
222f86b
a28e59d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| name: Database tests | ||
| on: | ||
| pull_request: | ||
| paths: | ||
| - "packages/database/**" | ||
| env: | ||
| SUPABASE_USE_DB: local | ||
| SUPABASE_PROJECT_ID: test | ||
| GITHUB_TEST: test | ||
|
|
||
| jobs: | ||
| build: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v6 | ||
| - name: Install pnpm | ||
| uses: pnpm/action-setup@v4 | ||
| with: | ||
| version: 10.15.1 | ||
| run_install: false | ||
| - name: Setup node | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: "20" | ||
| cache: "pnpm" | ||
| - name: Install Dependencies | ||
| run: pnpm install --frozen-lockfile | ||
| # - name: Get supabase version | ||
| # working-directory: ./packages/database | ||
| # run: echo "SUPABASE_VERSION=$(./node_modules/.bin/supabase --version)" >> $GITHUB_ENV | ||
| # - name: Cache Docker images. | ||
| # uses: AndreKurait/docker-cache@0.6.0 | ||
| # with: | ||
| # key: docker-${{ runner.os }}-${{ env.SUPABASE_VERSION }} | ||
| - name: Setup database | ||
| working-directory: ./packages/database | ||
| run: pnpm run setup | ||
| - name: Serve and run tests | ||
| working-directory: ./packages/database | ||
| run: pnpm run test:withserve |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,80 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| import { spawn, execSync } from "node:child_process"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| import { join, dirname } from "path"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| const scriptDir = dirname(__filename); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| const projectRoot = join(scriptDir, ".."); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| if ( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| process.env.GITHUB_ACTIONS === "true" && | ||||||||||||||||||||||||||||||||||||||||||||||||||
| process.env.GITHUB_TEST !== "test" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| console.error("Please set the GITHUB_TEST variable to 'test'"); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| process.exit(2); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| if (process.env.SUPABASE_PROJECT_ID !== "test") { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| console.error("Please set the SUPABASE_PROJECT_ID variable to 'test'"); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| process.exit(2); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| const serve = spawn("supabase", ["functions", "serve"], { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| cwd: projectRoot, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| detached: true, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| let resolveCallback: ((value: unknown) => void) | undefined = undefined; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| let rejectCallback: ((reason: unknown) => void) | undefined = undefined; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| let serveSuccess = false; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| let timeoutClear: NodeJS.Timeout | undefined = undefined; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| const servingReady = new Promise((rsc, rjc) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| resolveCallback = rsc; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| rejectCallback = rjc; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| // Add timeout | ||||||||||||||||||||||||||||||||||||||||||||||||||
| timeoutClear = setTimeout(() => { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| rjc(new Error("Timeout waiting for functions to serve")); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| }, 30000); // 30 second timeout | ||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| serve.stdout.on("data", (data: Buffer) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| const output = data.toString(); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| console.log(`stdout: ${output}`); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| if (output.includes("Serving functions ")) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| console.log("Found serving functions"); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| serveSuccess = true; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| clearTimeout(timeoutClear); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| if (resolveCallback === undefined) throw new Error("did not get callback"); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| resolveCallback(null); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| serve.on("close", () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!serveSuccess && rejectCallback) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| rejectCallback(new Error("serve closed without being ready")); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| serve.on("error", (err) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| if (rejectCallback) rejectCallback(err); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| const doTest = async () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| await servingReady; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| execSync("cucumber-js", { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| cwd: projectRoot, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| stdio: "inherit", | ||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| // will throw on failure | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } finally { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| if (serve.pid) process.kill(-serve.pid); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The finally {
if (serve.pid) {
try {
process.kill(-serve.pid);
} catch (e) {
// Process already exited, ignore
}
}
}
Suggested change
Spotted by Graphite
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔴 If the
Suggested change
Was this helpful? React with 👍 or 👎 to provide feedback. |
||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+58
to
+69
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Detached serve process never killed when In
Suggested change
Was this helpful? React with 👍 or 👎 to provide feedback. |
||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| doTest() | ||||||||||||||||||||||||||||||||||||||||||||||||||
| .then(() => { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| console.log("success"); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| clearTimeout(timeoutClear); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| .catch((err) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| console.error(err); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| clearTimeout(timeoutClear); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| process.exit(1); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔴 Unconsumed stderr pipe can deadlock the supabase serve child process
The
servechild process is spawned with the defaultstdio: 'pipe'for all streams (serve_and_test.ts:19-22). Whilestdouthas a'data'listener that drains it,stderrhas no listener at all. Ifsupabase functions servewrites more than the OS pipe buffer size (~64 KB on Linux) to stderr before writing "Serving functions" to stdout, the child process will block on its stderr write, never produce the expected stdout output, and the script will hit the 30-second timeout. This is a well-known Node.js child-process pitfall. The fix is to either addserve.stderr.resume()to drain stderr, pipe stderr to'inherit', or set it to'ignore'.Was this helpful? React with 👍 or 👎 to provide feedback.