Skip to content

Commit 6e89215

Browse files
MregXNshubham1172
andauthored
fix e2e test common/server/server.test.ts (#555)
* add delay to get everything ready Signed-off-by: MregXN <[email protected]> * Update test/e2e/common/server.test.ts Co-authored-by: Shubham Sharma <[email protected]> Signed-off-by: MregXN <[email protected]> --------- Signed-off-by: MregXN <[email protected]> Signed-off-by: MregXN <[email protected]> Co-authored-by: Shubham Sharma <[email protected]>
1 parent 4760695 commit 6e89215

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

test/e2e/common/server.test.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ limitations under the License.
1212
*/
1313

1414
import { CommunicationProtocolEnum, DaprServer, DaprPubSubStatusEnum } from "../../../src";
15+
import * as NodeJSUtil from "../../../src/utils/NodeJS.util";
1516

1617
const serverHost = "127.0.0.1";
1718
const serverGrpcPort = "50001";
@@ -49,6 +50,9 @@ const bulkSubscribeClodEventTopic = "bulk-subscribe-ce-topic";
4950
const bulkSubscribeCloudEventToRawPayloadTopic = "bulk-subscribe-ce-rp-topic";
5051
const bulkSubscribeRawPayloadToClodEventTopic = "bulk-subscribe-rp-ce-topic";
5152

53+
// Set timeout to 10s for all tests
54+
jest.setTimeout(10000);
55+
5256
describe("common/server", () => {
5357
let httpServer: DaprServer;
5458
let grpcServer: DaprServer;
@@ -134,9 +138,14 @@ describe("common/server", () => {
134138
});
135139

136140
await setupPubSubSubscriptions();
141+
// Sleep to make the tests less flaky.
142+
// TODO: https://github.com/dapr/js-sdk/issues/560
143+
await NodeJSUtil.sleep(2000);
137144

138145
await httpServer.start();
139146
await grpcServer.start();
147+
// Sleep for 2 seconds to get servers ready
148+
await NodeJSUtil.sleep(2000);
140149
});
141150

142151
beforeEach(() => {
@@ -161,7 +170,7 @@ describe("common/server", () => {
161170
const res = await server.client.pubsub.publish(pubSubName, getTopic(topicWithStatusCb, protocol), "SUCCESS");
162171
expect(res.error).toBeUndefined();
163172
// Delay a bit for event to arrive
164-
await new Promise((resolve, _reject) => setTimeout(resolve, 1000));
173+
await new Promise((resolve, _reject) => setTimeout(resolve, 2000));
165174
expect(mockSubscribeStatusHandler.mock.calls.length).toBe(1);
166175
expect(mockSubscribeStatusHandler.mock.calls[0][1]).toEqual("SUCCESS");
167176
expect(mockSubscribeDeadletterHandler.mock.calls.length).toBe(0);

0 commit comments

Comments
 (0)