Files
wehub-resource-sync b3a7f98e5a
CI / E2E Cloudflare (4/8) (push) Failing after 0s
CI / E2E Cloudflare (8/8) (push) Failing after 1s
CI / Lint (push) Failing after 1s
Auto Extract / Extract (push) Failing after 4s
CI / Version Check (push) Failing after 9s
CI / Integration Tests (push) Failing after 1s
CI / E2E tests (1/8) (push) Failing after 1s
CI / E2E tests (2/8) (push) Failing after 2s
CI / E2E tests (3/8) (push) Failing after 2s
CI / Browser Tests (push) Failing after 1s
CI / E2E tests (5/8) (push) Failing after 1s
CI / E2E Cloudflare (2/8) (push) Failing after 2s
CI / Typecheck (push) Failing after 1s
CI / Changeset Validation (push) Failing after 2s
CI / E2E Cloudflare (5/8) (push) Failing after 1s
CI / E2E Cloudflare (6/8) (push) Failing after 1s
CI / E2E Cloudflare (7/8) (push) Failing after 1s
CodeQL / Analyze (javascript-typescript) (push) Failing after 1s
Format / Format (push) Failing after 0s
CodeQL / Analyze (actions) (push) Failing after 4s
CI / E2E tests (4/8) (push) Failing after 1s
CI / E2E tests (6/8) (push) Failing after 1s
CI / E2E tests (7/8) (push) Failing after 2s
CI / E2E tests (8/8) (push) Failing after 1s
CI / E2E Cloudflare (1/8) (push) Failing after 1s
CI / E2E Cloudflare (3/8) (push) Failing after 2s
Preview Releases / Publish Preview (push) Failing after 0s
zizmor / Run zizmor (push) Failing after 1s
Release / Release (push) Failing after 2s
CI / Smoke Tests (push) Failing after 5m36s
CI / Tests (push) Failing after 6m36s
Release / Sync Templates (push) Has been skipped
CI / E2E Tests (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:23:53 +08:00

63 lines
2.3 KiB
TypeScript

/**
* Regression test for #1604.
*
* Integration suites boot a real Astro dev server each and vitest runs
* test files in parallel. Astro's "another dev server is already running"
* guard is scoped to the project root (a lockfile at `<root>/.astro/dev.json`),
* not to the port -- so when every suite shares one fixture directory, the
* second server to start aborts on the shared lock even though it requested a
* distinct port.
*
* This test reproduces that race inside a single suite: it boots two servers
* concurrently and asserts both come up and serve seeded content. Before the
* fix (servers run in-place from the shared fixture) the second server loses
* the lock and `createTestServer` times out. After the fix (each server gets
* its own copied fixture root) both succeed.
*/
import { describe, it, expect, afterAll } from "vitest";
import type { TestServerContext } from "../server.js";
import { assertNodeVersion, createTestServer } from "../server.js";
const PORT_A = 4402;
const PORT_B = 4403;
describe("Concurrent dev servers (#1604)", () => {
const contexts: TestServerContext[] = [];
afterAll(async () => {
await Promise.all(contexts.map((ctx) => ctx.cleanup()));
});
it("boots two servers from the same fixture in parallel without colliding on the Astro lock", async () => {
assertNodeVersion();
// Track each server the moment it starts so a partial failure (one boots,
// the other rejects) still leaves the successful server cleanable in
// afterAll -- Promise.all would otherwise short-circuit before we push it.
async function startTracked(port: number): Promise<TestServerContext> {
const ctx = await createTestServer({ port });
contexts.push(ctx);
return ctx;
}
// Start both concurrently so they race for the (previously shared) lock.
const [a, b] = await Promise.all([startTracked(PORT_A), startTracked(PORT_B)]);
// Distinct roots -- the fix gives each server its own copied fixture.
expect(a.cwd).not.toBe(b.cwd);
// Both must actually serve their independently seeded content.
const [collectionsA, collectionsB] = await Promise.all([
a.client.collections(),
b.client.collections(),
]);
for (const collections of [collectionsA, collectionsB]) {
const slugs = collections.map((c: { slug: string }) => c.slug);
expect(slugs).toContain("posts");
expect(slugs).toContain("pages");
}
});
});