Skip to content

Commit fee9b35

Browse files
anuj-kumaryJatin Masaram
authored andcommitted
test: fix race condition for upload files (open-metadata#27650)
* test: resolve flaky CSVImportWithQuotesAndCommas test due to timeout race condition * fix lint issue
1 parent 10b099e commit fee9b35

2 files changed

Lines changed: 17 additions & 10 deletions

File tree

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -538,9 +538,13 @@ export const uploadCSVAndWaitForGrid = async (
538538
}
539539

540540
await page.setInputFiles('[type="file"]', actualFilePath);
541-
await page.getByTestId('upload-file-widget').waitFor({ state: 'hidden' });
541+
await page
542+
.getByTestId('upload-file-widget')
543+
.waitFor({ state: 'hidden', timeout: 30000 });
542544

543-
await expect(page.locator('.rdg-header-row')).toBeVisible();
545+
await page
546+
.locator('.rdg-header-row')
547+
.waitFor({ state: 'visible', timeout: 30000 });
544548
const rowCount = await page.locator('.rdg-row').count();
545549
return { rowCount, tempFilePath };
546550
};

openmetadata-ui/src/main/resources/ui/src/components/UploadFile/UploadFile.tsx

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,23 @@ const UploadFile: FC<UploadFileProps> = ({
3535
const handleUpload: UploadProps['customRequest'] = useCallback(
3636
(options: UploadRequestOption) => {
3737
setUploading(true);
38+
const reader = new FileReader();
39+
reader.onload = (e) => {
40+
setUploading(false);
41+
onCSVUploaded(e);
42+
};
43+
reader.onerror = () => {
44+
setUploading(false);
45+
showErrorToast(new Error(t('server.unexpected-error')) as AxiosError);
46+
};
3847
try {
39-
const reader = new FileReader();
40-
reader.onload = onCSVUploaded;
41-
reader.onerror = () => {
42-
throw t('server.unexpected-error');
43-
};
4448
reader.readAsText(options.file as Blob);
4549
} catch (error) {
46-
showErrorToast(error as AxiosError);
47-
} finally {
4850
setUploading(false);
51+
showErrorToast(error as AxiosError);
4952
}
5053
},
51-
[onCSVUploaded]
54+
[onCSVUploaded, t]
5255
);
5356

5457
return uploading ? (

0 commit comments

Comments
 (0)