Skip to content

Commit 4b61290

Browse files
committed
trying to fix flaky ws failing tests
1 parent 47b8e2f commit 4b61290

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
@@ -1832,17 +1832,15 @@ class ApiGateway {
18321832
if (props.queryType === 'multi') {
18331833
// We prepare the final json result on native side
18341834
const resultMulti = new ResultMultiWrapper(results, { queryType, slowQuery });
1835-
return res(resultMulti);
1835+
await res(resultMulti);
18361836
} else {
18371837
// We prepare the full final json result on native side
1838-
return res(results[0]);
1838+
await res(results[0]);
18391839
}
18401840
} catch (e: any) {
18411841
this.handleError({
18421842
e, context, query, res, requestStarted
18431843
});
1844-
1845-
return null;
18461844
}
18471845
}
18481846

@@ -1934,7 +1932,7 @@ class ApiGateway {
19341932
}];
19351933
}
19361934

1937-
return res(request.streaming ? results[0] : { results });
1935+
await res(request.streaming ? results[0] : { results });
19381936
} else {
19391937
results = await Promise.all(
19401938
normalizedQueries.map(async (normalizedQuery, index) => {
@@ -1968,19 +1966,17 @@ class ApiGateway {
19681966
);
19691967

19701968
if (request.streaming) {
1971-
return res(results[0]);
1969+
await res(results[0]);
19721970
} else {
19731971
// We prepare the final json result on native side
19741972
const resultArray = new ResultArrayWrapper(results);
1975-
return res(resultArray);
1973+
await res(resultArray);
19761974
}
19771975
}
19781976
} catch (e: any) {
19791977
this.handleError({
19801978
e, context, query, res, requestStarted
19811979
});
1982-
1983-
return null;
19841980
}
19851981
}
19861982

0 commit comments

Comments
 (0)