Files
bruno/tests/sse/sse-cancellation.spec.ts
Chirag Chandrashekhar 5e1a36f8c8 fix: close previous SSE connection before sending new request (#7474)
* fix: update system proxy fetching to use finally (#7652)

* fix: update system proxy fetching to use finally for improved reliability

* Update packages/bruno-electron/src/index.js

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* fix: allow file selection in multipart form without entering a key first (#7640)

* fix: close previous SSE connection before sending new request

When resending an SSE (Server-Sent Events) request using Cmd+Enter,
the previous connection was not being closed, causing connection leaks.

Changes:
- Add SSE cancellation logic to sendRequest action - checks for running
  stream and cancels it before sending new request
- Add return to cancelRequest action to make it properly chainable
- Simplify RequestTabPanel by removing duplicate cancel logic (now
  handled centrally in sendRequest)
- Add SSE endpoints to test server for e2e testing
- Add Playwright e2e test to verify SSE connection cancellation

* fix: address PR review feedback for SSE connection cancellation

- Use platform-aware modifier (Meta on macOS, Control on Linux/Windows)
  instead of hardcoded Meta+Enter for cross-platform CI compatibility
- Replace waitForTimeout with expect.poll for deterministic assertions
- Remove dead try/catch around cancelRequest (errors already swallowed
  by cancelRequest's internal .catch)

* fix: updated the test to check of connectionIds

---------

Co-authored-by: Sid <siddharth@usebruno.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Pooja <pooja@usebruno.com>
Co-authored-by: Chirag Chandrashekhar <cchirag85@gmail.com>
2026-04-03 01:59:11 +05:30

37 lines
1.5 KiB
TypeScript

import { test, expect } from '../../playwright';
test.describe('SSE Connection Cancellation', () => {
test.beforeEach(async ({ pageWithUserData: page }) => {
// Reset SSE connections before each test
await page.request.post('http://localhost:8081/api/sse/reset');
});
test('should close previous SSE connection when resending request', async ({ pageWithUserData: page }) => {
await page.locator('#sidebar-collection-name').click();
await page.getByTestId('sidebar-collection-item-row').filter({ hasText: 'sse-stream-request' }).click();
await page.getByTestId('send-arrow-icon').waitFor({ state: 'visible' });
await page.getByTestId('send-arrow-icon').click();
// Poll until the SSE connection is established
await expect.poll(async () => {
const response = await page.request.get('http://localhost:8081/api/sse/connections');
const data = await response.json();
return data.connectionIds;
}, { timeout: 5000 }).toStrictEqual([1]);
// Resend the request (this should cancel the old connection and start a new one)
const resendShortcut = process.platform === 'darwin' ? 'Meta+Enter' : 'Control+Enter';
await page.keyboard.press(resendShortcut);
// Poll until the old connection is closed and a new one is established
await expect.poll(async () => {
const response = await page.request.get('http://localhost:8081/api/sse/connections');
const data = await response.json();
return data.connectionIds;
}, { timeout: 5000 }).toStrictEqual([2]);
});
});