@@ -12,6 +12,7 @@ limitations under the License.
12
12
*/
13
13
14
14
import { CommunicationProtocolEnum , DaprServer , DaprPubSubStatusEnum } from "../../../src" ;
15
+ import * as NodeJSUtil from "../../../src/utils/NodeJS.util" ;
15
16
16
17
const serverHost = "127.0.0.1" ;
17
18
const serverGrpcPort = "50001" ;
@@ -49,6 +50,9 @@ const bulkSubscribeClodEventTopic = "bulk-subscribe-ce-topic";
49
50
const bulkSubscribeCloudEventToRawPayloadTopic = "bulk-subscribe-ce-rp-topic" ;
50
51
const bulkSubscribeRawPayloadToClodEventTopic = "bulk-subscribe-rp-ce-topic" ;
51
52
53
+ // Set timeout to 10s for all tests
54
+ jest . setTimeout ( 10000 ) ;
55
+
52
56
describe ( "common/server" , ( ) => {
53
57
let httpServer : DaprServer ;
54
58
let grpcServer : DaprServer ;
@@ -134,9 +138,14 @@ describe("common/server", () => {
134
138
} ) ;
135
139
136
140
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 ) ;
137
144
138
145
await httpServer . start ( ) ;
139
146
await grpcServer . start ( ) ;
147
+ // Sleep for 2 seconds to get servers ready
148
+ await NodeJSUtil . sleep ( 2000 ) ;
140
149
} ) ;
141
150
142
151
beforeEach ( ( ) => {
@@ -161,7 +170,7 @@ describe("common/server", () => {
161
170
const res = await server . client . pubsub . publish ( pubSubName , getTopic ( topicWithStatusCb , protocol ) , "SUCCESS" ) ;
162
171
expect ( res . error ) . toBeUndefined ( ) ;
163
172
// 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 ) ) ;
165
174
expect ( mockSubscribeStatusHandler . mock . calls . length ) . toBe ( 1 ) ;
166
175
expect ( mockSubscribeStatusHandler . mock . calls [ 0 ] [ 1 ] ) . toEqual ( "SUCCESS" ) ;
167
176
expect ( mockSubscribeDeadletterHandler . mock . calls . length ) . toBe ( 0 ) ;
0 commit comments