Skip to content

Commit d72f2f2

Browse files
committed
fix(test-utils): Use server time for listener registration, not client time
The listener was using the client's timestamp from the query param, but due to network latency, events could be buffered between when the client generated its timestamp and when the HTTP request reached the server. Timeline of the bug: 1. Client: T1 = 1000ms (generates timestamp) 2. Client: Sends HTTP request with ?timestamp=1000 3. [NETWORK DELAY] 4. Previous test's event arrives at proxy at T2 = 1002ms (buffered!) 5. Server receives HTTP request at T3 = 1003ms 7. Buffer check: 1002 > 1000 = TRUE → stale event passes! Fix: Use the server's current time when the listener is actually registered. This ensures we only receive events that arrived AFTER the listener was registered on the server.
1 parent bae7fb6 commit d72f2f2

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,12 @@ export async function startProxyServer(
133133
eventCallbackResponse.statusCode = 200;
134134
eventCallbackResponse.setHeader('connection', 'keep-alive');
135135

136-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
137-
const searchParams = new URL(eventCallbackRequest.url!, 'http://justsomerandombasesothattheurlisparseable.com/')
138-
.searchParams;
139-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
140-
const listenerTimestamp = Number(searchParams.get('timestamp')!);
136+
// CRITICAL: Use the SERVER's current time when the listener is actually registered,
137+
// NOT the client timestamp from the query param. Due to network latency, events may
138+
// have been buffered between when the client generated its timestamp and when the
139+
// HTTP request reached this server. Using server time ensures we only get events
140+
// that arrived AFTER the listener was actually registered on the server.
141+
const listenerTimestamp = getTimestamp();
141142

142143
const callbackListener: EventCallbackListener = {
143144
callback: (data: string): void => {

0 commit comments

Comments
 (0)