Skip to content

Commit e5c7fea

Browse files
committed
trying to fix flaky ws failing tests
1 parent 73bced9 commit e5c7fea

File tree

2 files changed

+7
-11
lines changed

2 files changed

+7
-11
lines changed

packages/cubejs-api-gateway/src/SubscriptionServer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const calcMessageLength = (message: unknown) => Buffer.byteLength(
1919
typeof message === 'string' ? message : JSON.stringify(message)
2020
);
2121

22-
export type WebSocketSendMessageFn = (connectionId: string, message: any) => void;
22+
export type WebSocketSendMessageFn = (connectionId: string, message: any) => Promise<void>;
2323

2424
export class SubscriptionServer {
2525
public constructor(
@@ -31,7 +31,7 @@ export class SubscriptionServer {
3131
}
3232

3333
public resultFn(connectionId: string, messageId: string, requestId: string | undefined) {
34-
return (message, { status } = { status: 200 }) => {
34+
return async (message, { status } = { status: 200 }) => {
3535
this.apiGateway.log({
3636
type: 'Outgoing network usage',
3737
service: 'api-ws',

packages/cubejs-api-gateway/src/gateway.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1812,17 +1812,15 @@ class ApiGateway {
18121812
if (props.queryType === 'multi') {
18131813
// We prepare the final json result on native side
18141814
const resultMulti = new ResultMultiWrapper(results, { queryType, slowQuery });
1815-
return res(resultMulti);
1815+
await res(resultMulti);
18161816
} else {
18171817
// We prepare the full final json result on native side
1818-
return res(results[0]);
1818+
await res(results[0]);
18191819
}
18201820
} catch (e: any) {
18211821
this.handleError({
18221822
e, context, query, res, requestStarted
18231823
});
1824-
1825-
return null;
18261824
}
18271825
}
18281826

@@ -1914,7 +1912,7 @@ class ApiGateway {
19141912
}];
19151913
}
19161914

1917-
return res(request.streaming ? results[0] : { results });
1915+
await res(request.streaming ? results[0] : { results });
19181916
} else {
19191917
results = await Promise.all(
19201918
normalizedQueries.map(async (normalizedQuery, index) => {
@@ -1948,19 +1946,17 @@ class ApiGateway {
19481946
);
19491947

19501948
if (request.streaming) {
1951-
return res(results[0]);
1949+
await res(results[0]);
19521950
} else {
19531951
// We prepare the final json result on native side
19541952
const resultArray = new ResultArrayWrapper(results);
1955-
return res(resultArray);
1953+
await res(resultArray);
19561954
}
19571955
}
19581956
} catch (e: any) {
19591957
this.handleError({
19601958
e, context, query, res, requestStarted
19611959
});
1962-
1963-
return null;
19641960
}
19651961
}
19661962

0 commit comments

Comments
 (0)