@@ -26,6 +26,7 @@ describe('grpc/main', () => {
26
26
let client : DaprClient ;
27
27
const mockBindingReceive = jest . fn ( async ( _data : object ) => console . log ( 'mockBindingReceive' ) ) ;
28
28
const mockPubSubSubscribe = jest . fn ( async ( _data : object ) => console . log ( 'mockPubSubSubscribe' ) ) ;
29
+ const mockPubSubSubscribeError = jest . fn ( async ( _data : object ) => { throw new Error ( "mockPubSubSubscribeError" ) } ) ;
29
30
30
31
// We need to start listening on some endpoints already
31
32
// this because Dapr is not dynamic and registers endpoints on boot
@@ -38,6 +39,7 @@ describe('grpc/main', () => {
38
39
// Test with:
39
40
// dapr publish --publish-app-id test-suite --pubsub pubsub-redis --topic test-topic --data '{ "hello": "world" }'
40
41
await server . pubsub . subscribe ( 'pubsub-redis' , 'test-topic' , mockPubSubSubscribe ) ;
42
+ await server . pubsub . subscribe ( 'pubsub-redis' , 'test-topic-error' , mockPubSubSubscribeError ) ;
41
43
42
44
// Start server
43
45
await server . start ( ) ;
@@ -109,6 +111,19 @@ describe('grpc/main', () => {
109
111
const res = await client . pubsub . publish ( 'pubsub-redis' , 'test-topic' , { hello : 'world' } ) ;
110
112
expect ( res ) . toEqual ( true ) ;
111
113
} ) ;
114
+
115
+ it ( 'should not crash if the callback throws an error' , async ( ) => {
116
+ await client . pubsub . publish ( 'pubsub-redis' , 'test-topic-error' , { hello : 'world' } ) ;
117
+
118
+ // Delay a bit for event to arrive
119
+ await new Promise ( ( resolve , _reject ) => setTimeout ( resolve , 250 ) ) ;
120
+
121
+ expect ( mockPubSubSubscribeError . mock . calls . length ) . toBe ( 1 ) ;
122
+
123
+ // Also test for receiving data
124
+ // @ts -ignore
125
+ expect ( mockPubSubSubscribeError . mock . calls [ 0 ] [ 0 ] [ 'hello' ] ) . toEqual ( 'world' ) ;
126
+ } ) ;
112
127
} ) ;
113
128
114
129
describe ( 'invoker' , ( ) => {
0 commit comments