tests/browser/server.py accepts --port 0: it binds 127.0.0.1:0 before building the app, holds that socket for its whole life and prints PM_TEST_SERVER_PORT=<n> to stdout. startBrowserServer defaults to port 0 and reads the announced port, so no port is reserved and released before the server binds and two launchers can no longer race for one. The "address already in use" retry and free-port.mjs are gone; --port N still works and is checked against the announcement.
36 lines
1.7 KiB
JavaScript
36 lines
1.7 KiB
JavaScript
// Each Playwright worker owns its server: `request`, `page` and manual
|
|
// `browser.newContext()` all reach it through `baseURL`, and another server
|
|
// process never sees its database.
|
|
import { test, expect } from './fixtures.mjs';
|
|
import { startBrowserServer } from '../../tools/vendor/start-browser-server.mjs';
|
|
|
|
const search = text => `/prompt_manager/search?text=${encodeURIComponent(text)}`;
|
|
|
|
test('every fixture reaches this worker\'s own server and another server keeps its own database', async ({ request, page, browser, baseURL, workerServer }, testInfo) => {
|
|
expect(baseURL).toBe(workerServer.url);
|
|
await expect(await request.post('/__test__/reset')).toBeOK();
|
|
const marker = `worker ${testInfo.workerIndex} isolation ${testInfo.project.name} ${testInfo.repeatEachIndex}`;
|
|
await expect(await request.post('/prompt_manager/save', { data: { text: marker } })).toBeOK();
|
|
expect((await (await request.get(search(marker))).json()).count).toBe(1);
|
|
|
|
const viaPage = await page.request.get(search(marker));
|
|
expect(viaPage.url().startsWith(`${baseURL}/`)).toBe(true);
|
|
expect((await viaPage.json()).count).toBe(1);
|
|
const context = await browser.newContext();
|
|
try {
|
|
const response = await (await context.newPage()).goto(search(marker));
|
|
expect(response.url().startsWith(`${baseURL}/`)).toBe(true);
|
|
expect((await response.json()).count).toBe(1);
|
|
} finally {
|
|
await context.close();
|
|
}
|
|
|
|
const other = await startBrowserServer();
|
|
try {
|
|
expect(other.url).not.toBe(baseURL);
|
|
expect((await (await fetch(`${other.url}${search(marker)}`)).json()).count).toBe(0);
|
|
} finally {
|
|
await other.stop();
|
|
}
|
|
});
|