Skip to content

Commit 6c33831

Browse files
committed
test: fix CSV import Playwright test timeout by awaiting WebSocket completion before grid render (#27806)
(cherry picked from commit b68e744)
1 parent b9cb87d commit 6c33831

3 files changed

Lines changed: 43 additions & 6 deletions

File tree

openmetadata-ui/src/main/resources/ui/playwright/e2e/Pages/CSVImportWithQuotesAndCommas.spec.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
validateImportStatus,
2020
waitForImportGridLoadMaskToDisappear,
2121
} from '../../utils/importUtils';
22+
import { setupCsvImportListener } from '../../utils/websocket';
2223

2324
const cleanupTempFile = (filePath: string | undefined): void => {
2425
if (filePath && fs.existsSync(filePath)) {
@@ -40,7 +41,10 @@ const CSV_WITH_QUOTES_AND_COMMAS = `parent,name*,displayName,description,synonym
4041
,"TermWithComma,AndQuote","Display name with ""quoted"" text, and comma","<p>Description with ""quotes"" and, commas</p>",,,,,,user:admin,Approved,,,`;
4142

4243
test.describe('CSV Import with Commas and Quotes - All Entity Types', () => {
44+
let createCsvImportPromise: () => Promise<void>;
45+
4346
test.beforeEach(async ({ page }) => {
47+
createCsvImportPromise = await setupCsvImportListener(page);
4448
await redirectToHomePage(page);
4549
});
4650

@@ -67,6 +71,7 @@ test.describe('CSV Import with Commas and Quotes - All Entity Types', () => {
6771
{
6872
isContentString: true,
6973
tempFileName: `temp-quotes-commas-${uuid()}.csv`,
74+
csvImportCompletedPromise: createCsvImportPromise(),
7075
}
7176
);
7277
tempFilePath = tempFile;
@@ -148,7 +153,9 @@ test.describe('CSV Import with Commas and Quotes - All Entity Types', () => {
148153
await page.click('[data-testid="import-button-description"]');
149154

150155
try {
151-
await uploadCSVAndWaitForGrid(page, exportedCsvPath);
156+
await uploadCSVAndWaitForGrid(page, exportedCsvPath, {
157+
csvImportCompletedPromise: createCsvImportPromise(),
158+
});
152159

153160
await expect(
154161
page.getByRole('gridcell', { name: 'Term1' }).first()

openmetadata-ui/src/main/resources/ui/playwright/utils/importUtils.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -523,9 +523,11 @@ export const uploadCSVAndWaitForGrid = async (
523523
options?: {
524524
isContentString?: boolean;
525525
tempFileName?: string;
526+
csvImportCompletedPromise?: Promise<void>;
526527
}
527528
): Promise<{ rowCount: number; tempFilePath?: string }> => {
528-
await page.locator('[type="file"]').waitFor({ state: 'attached' });
529+
const uploadWidget = page.getByTestId('upload-file-widget');
530+
await uploadWidget.waitFor({ state: 'attached' });
529531
let actualFilePath = filePath;
530532
let tempFilePath: string | undefined;
531533

@@ -537,10 +539,11 @@ export const uploadCSVAndWaitForGrid = async (
537539
actualFilePath = tempFilePath;
538540
}
539541

540-
await page.setInputFiles('[type="file"]', actualFilePath);
541-
await page
542-
.getByTestId('upload-file-widget')
543-
.waitFor({ state: 'hidden', timeout: 30000 });
542+
await uploadWidget.setInputFiles([actualFilePath]);
543+
544+
if (options?.csvImportCompletedPromise) {
545+
await options.csvImportCompletedPromise;
546+
}
544547

545548
await page
546549
.locator('.rdg-header-row')

openmetadata-ui/src/main/resources/ui/playwright/utils/websocket.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,3 +161,30 @@ export const cleanupWebSocketMock = () => {
161161
defaultMock = null;
162162
}
163163
};
164+
165+
export const setupCsvImportListener = async (
166+
page: Page,
167+
urlPattern = /push\/feed/
168+
): Promise<() => Promise<void>> => {
169+
const pendingResolvers: Array<() => void> = [];
170+
171+
await page.routeWebSocket(urlPattern, (ws) => {
172+
const server = ws.connectToServer();
173+
174+
server.onMessage((message) => {
175+
ws.send(message);
176+
const data =
177+
typeof message === 'string' ? message : message.toString('utf-8');
178+
179+
if (data.includes('csvImportChannel') && data.includes('COMPLETED')) {
180+
pendingResolvers.shift()?.();
181+
}
182+
});
183+
184+
ws.onMessage((message) => {
185+
server.send(message);
186+
});
187+
});
188+
189+
return () => new Promise<void>((resolve) => pendingResolvers.push(resolve));
190+
};

0 commit comments

Comments
 (0)