Skip to content

Commit 87f6dc6

Browse files
committed
fix(test-utils): Use >= for live events, > only for buffered events
Live events arriving at the same millisecond as listener registration were being filtered out, causing tests to timeout waiting for events that never arrived. - Buffered events: Use > (strict) - they might be from before registration - Live events: Use >= - they are guaranteed to be new, not stale This fixes the test timeouts while still preventing stale buffered events from leaking through.
1 parent d72f2f2 commit 87f6dc6

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

dev-packages/test-utils/src/event-proxy-server.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,11 @@ export async function startProxyServer(
9696
const eventTimestamp = getTimestamp();
9797
eventBuffer.push({ data: proxyRequestBody, timestamp: eventTimestamp });
9898

99-
// Only send to listeners that registered BEFORE this event was received.
100-
// This prevents stale events from previous tests leaking to newer listeners.
99+
// Send to listeners that registered BEFORE or AT THE SAME TIME as this event.
100+
// Use >= for live events because they're guaranteed to be new (not stale).
101+
// The strict > is only needed for buffered events which might be from before.
101102
eventCallbackListeners.forEach(listener => {
102-
if (eventTimestamp > listener.registeredAt) {
103+
if (eventTimestamp >= listener.registeredAt) {
103104
listener.callback(proxyRequestBody);
104105
}
105106
});
@@ -207,10 +208,11 @@ export async function startEventProxyServer(options: EventProxyServerOptions): P
207208
const eventTimestamp = getTimestamp();
208209
eventBuffer.push({ data: dataString, timestamp: eventTimestamp });
209210

210-
// Only send to listeners that registered BEFORE this event was received.
211-
// This prevents stale events from previous tests leaking to newer listeners.
211+
// Send to listeners that registered BEFORE or AT THE SAME TIME as this event.
212+
// Use >= for live events because they're guaranteed to be new (not stale).
213+
// The strict > is only needed for buffered events which might be from before.
212214
eventCallbackListeners.forEach(listener => {
213-
if (eventTimestamp > listener.registeredAt) {
215+
if (eventTimestamp >= listener.registeredAt) {
214216
listener.callback(dataString);
215217
}
216218
});

0 commit comments

Comments
 (0)