bito-code-review[bot] commented on code in PR #42305:
URL: https://github.com/apache/superset/pull/42305#discussion_r3628973908
##########
superset-frontend/src/middleware/asyncEvent.test.ts:
##########
@@ -130,6 +130,42 @@ describe('asyncEvent middleware', () => {
expect(fetchMock.callHistory.calls(CACHED_DATA_ENDPOINT)).toHaveLength(1);
});
+ test('rejects with an AbortError and cancels the job when the signal
aborts', async () => {
+ const CANCEL_ENDPOINT = 'glob:*/api/v1/async_event/*/cancel';
+ fetchMock.post(CANCEL_ENDPOINT, { status: 200, body: {} });
+
+ const controller = new AbortController();
+ const promise = asyncEvent.waitForAsyncData(
+ asyncPendingEvent,
+ controller.signal,
+ );
+ controller.abort();
+
+ let error: any = null;
+ try {
+ await promise;
+ } catch (err) {
+ error = err;
+ }
+ expect(error?.name).toBe('AbortError');
+ // The cancel POST is fire-and-forget; let its microtask flush.
+ await new Promise(resolve => setTimeout(resolve, 0));
+ expect(fetchMock.callHistory.calls(CANCEL_ENDPOINT)).toHaveLength(1);
+ });
+
+ test('rejects immediately when given an already-aborted signal', async ()
=> {
+ const CANCEL_ENDPOINT = 'glob:*/api/v1/async_event/*/cancel';
+ fetchMock.post(CANCEL_ENDPOINT, { status: 200, body: {} });
+
+ const controller = new AbortController();
+ controller.abort();
+
+ await expect(
+ asyncEvent.waitForAsyncData(asyncPendingEvent, controller.signal),
+ ).rejects.toMatchObject({ name: 'AbortError' });
+ expect(fetchMock.callHistory.calls(CANCEL_ENDPOINT)).toHaveLength(1);
Review Comment:
<div>
<div id="suggestion">
<div id="issue"><b>Missing microtask flush for fire-and-forget POST</b></div>
<div id="fix">
The cancel POST is fire-and-forget per implementation (`cancelAsyncJob` at
asyncEvent.ts:105-112), but this test doesn't flush microtasks before asserting
the endpoint was called, unlike the equivalent test at line 152. This
inconsistency can cause flaky test failures in CI environments where async
operations complete after assertions run.
</div>
</div>
<small><i>Code Review Run #0d77a5</i></small>
</div>
---
Should Bito avoid suggestions like this for future reviews? (<a
href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>)
- [ ] Yes, avoid them
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]