Skip to content

Commit

Permalink
fix(ui-mode): prevent websocket connection leaks on reload (#33643)
Browse files Browse the repository at this point in the history
  • Loading branch information
ruifigueira authored Nov 18, 2024
1 parent 46321e5 commit 82c77a5
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packages/trace-viewer/src/ui/uiModeView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,10 @@ export const UIModeView: React.FC<{}> = ({
const inputRef = React.useRef<HTMLInputElement>(null);

const reloadTests = React.useCallback(() => {
setTestServerConnection(new TestServerConnection(new WebSocketTestServerTransport(wsURL)));
setTestServerConnection(prevConnection => {
prevConnection?.close();
return new TestServerConnection(new WebSocketTestServerTransport(wsURL));
});
}, []);

// Load tests on startup.
Expand Down Expand Up @@ -224,7 +227,7 @@ export const UIModeView: React.FC<{}> = ({
newFilter.set(projectSuite.title, !!selectedProjects?.includes(projectSuite.title));
}
if (!selectedProjects && newFilter.size && ![...newFilter.values()].includes(true))
newFilter.set(newFilter.entries().next().value[0], true);
newFilter.set(newFilter.entries().next().value![0], true);
if (projectFilters.size !== newFilter.size || [...projectFilters].some(([k, v]) => newFilter.get(k) !== v))
setProjectFilters(newFilter);
}, [projectFilters, testModel]);
Expand Down
23 changes: 23 additions & 0 deletions tests/playwright-test/ui-mode-test-run.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -775,3 +775,26 @@ test('should respect --ignore-snapshots option', {
- treeitem ${/\[icon-check\] snapshot/}
`);
});

test('should not leak websocket connections', {
annotation: { type: 'issue', description: 'https://github.com/microsoft/playwright/issues/33641' }
}, async ({ runUITest }) => {
const { page } = await runUITest({
'a.test.ts': `
import { test, expect } from '@playwright/test';
test('test', async () => {});
`,
});

const [ws1] = await Promise.all([
page.waitForEvent('websocket'),
page.getByTitle('Reload').click(),
]);

await Promise.all([
page.waitForEvent('websocket'),
page.getByTitle('Reload').click(),
]);

await expect.poll(() => ws1.isClosed()).toBe(true);
});

0 comments on commit 82c77a5

Please sign in to comment.