Skip to content

Commit 24832b2

Browse files
authored
[ui-core] fix race condition resulting in flaky unit test (#33042)
## Summary & Motivation Attempt to fix flaky test: ``` [2025-12-12T20:05:57Z] FAIL src/assets/__tests__/AssetCatalogTablev2.test.tsx (5.841 s, 520 MB heap size) [2025-12-12T20:05:57Z] ● AssetCatalogTableV2 › renders [2025-12-12T20:05:57Z] [2025-12-12T20:05:57Z] expect(received).toEqual(expected) // deep equality [2025-12-12T20:05:57Z] [2025-12-12T20:05:57Z] - Expected - 2 [2025-12-12T20:05:57Z] + Received + 14 [2025-12-12T20:05:57Z] [2025-12-12T20:05:57Z] - ObjectContaining { [2025-12-12T20:05:57Z] - "healthDataLoading": false, [2025-12-12T20:05:57Z] + Object { [2025-12-12T20:05:57Z] + "allGroups": Array [ [2025-12-12T20:05:57Z] + "Degraded", [2025-12-12T20:05:57Z] + "Warning", [2025-12-12T20:05:57Z] + "Healthy", [2025-12-12T20:05:57Z] + "Unknown", [2025-12-12T20:05:57Z] + ], [2025-12-12T20:05:57Z] + "checkedDisplayKeys": Set {}, [2025-12-12T20:05:57Z] + "grouped": Object {}, [2025-12-12T20:05:57Z] + "healthDataLoading": true, [2025-12-12T20:05:57Z] + "id": "asset-catalog-table-health_status", [2025-12-12T20:05:57Z] + "loading": false, [2025-12-12T20:05:57Z] + "onToggleFactory": [Function onToggleFactory], [2025-12-12T20:05:57Z] + "onToggleGroup": [Function anonymous], [2025-12-12T20:05:57Z] } ``` - props is a reference to a specific object from a specific render - When the component re-renders with healthDataLoading: false, it creates a NEW props object - The waitFor keeps checking the OLD props object which never changes - Sometimes passes if health data loads before we capture props - Sometimes fails if we capture props during loading Move props retrieval inside the waitFor callback to get fresh props on each poll: ``` await waitFor(() => { const calls = (AssetCatalogV2VirtualizedTable as unknown as jest.Mock).mock.calls; const props = calls[calls.length - 1][0]; expect(props).toEqual( expect.objectContaining({ healthDataLoading: false, }), ); }); ``` Now each poll gets the latest mock call → checks current props → passes when health data is loaded. ## How I Tested These Changes bk ## Changelog NOCHANGELOG
1 parent 32e0aa2 commit 24832b2

1 file changed

Lines changed: 12 additions & 10 deletions

File tree

js_modules/dagster-ui/packages/ui-core/src/assets/__tests__/AssetCatalogTablev2.test.tsx

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -204,16 +204,18 @@ describe('AssetCatalogTableV2', () => {
204204
expect(resultFn).toHaveBeenCalled();
205205
});
206206

207-
const calls = (AssetCatalogV2VirtualizedTable as unknown as jest.Mock).mock.calls;
208-
const props = calls[calls.length - 1][0];
209-
await waitFor(() =>
207+
await waitFor(() => {
208+
const calls = (AssetCatalogV2VirtualizedTable as unknown as jest.Mock).mock.calls;
209+
const props = calls[calls.length - 1][0];
210210
expect(props).toEqual(
211211
expect.objectContaining({
212212
healthDataLoading: false,
213213
}),
214-
),
215-
);
214+
);
215+
});
216216

217+
const calls = (AssetCatalogV2VirtualizedTable as unknown as jest.Mock).mock.calls;
218+
const props = calls[calls.length - 1][0];
217219
expect(props).toEqual(
218220
expect.objectContaining({
219221
checkedDisplayKeys: new Set(),
@@ -271,9 +273,9 @@ describe('AssetCatalogTableV2', () => {
271273
expect(resultFn).toHaveBeenCalled();
272274
});
273275

274-
const calls = (AssetCatalogV2VirtualizedTable as unknown as jest.Mock).mock.calls;
275-
const props = calls[calls.length - 1][0];
276-
await waitFor(() =>
276+
await waitFor(() => {
277+
const calls = (AssetCatalogV2VirtualizedTable as unknown as jest.Mock).mock.calls;
278+
const props = calls[calls.length - 1][0];
277279
expect(props).toEqual(
278280
expect.objectContaining({
279281
checkedDisplayKeys: new Set(['asset1', 'asset2']),
@@ -288,7 +290,7 @@ describe('AssetCatalogTableV2', () => {
288290
}),
289291
}),
290292
}),
291-
),
292-
);
293+
);
294+
});
293295
});
294296
});

0 commit comments

Comments
 (0)