@@ -12,6 +12,7 @@ limitations under the License.
1212*/
1313
1414import { CommunicationProtocolEnum , DaprServer , DaprPubSubStatusEnum } from "../../../src" ;
15+ import * as NodeJSUtil from "../../../src/utils/NodeJS.util" ;
1516
1617const serverHost = "127.0.0.1" ;
1718const serverGrpcPort = "50001" ;
@@ -49,6 +50,9 @@ const bulkSubscribeClodEventTopic = "bulk-subscribe-ce-topic";
4950const bulkSubscribeCloudEventToRawPayloadTopic = "bulk-subscribe-ce-rp-topic" ;
5051const bulkSubscribeRawPayloadToClodEventTopic = "bulk-subscribe-rp-ce-topic" ;
5152
53+ // Set timeout to 10s for all tests
54+ jest . setTimeout ( 10000 ) ;
55+
5256describe ( "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