@@ -320,6 +320,51 @@ func TestRawMessageHandling(t *testing.T) {
320
320
proceedOrTimeout (2 , proceed , nil , t )
321
321
}
322
322
323
+ func TestGlobalRawMessageHandlingErr (t * testing.T ) {
324
+ metrics .ResetRejectedMessagesCounter ()
325
+ /*
326
+ tests issues:
327
+ https://github.com/wework/grabbit/issues/187
328
+ https://github.com/wework/grabbit/issues/188
329
+ */
330
+ var otherHandlerCalled bool
331
+
332
+ handler := func (tx * sql.Tx , delivery * amqp.Delivery ) error {
333
+
334
+ return errors .New ("other handlers should not be called" )
335
+ }
336
+
337
+ //this handler should not be invoked by the bus, if it does the test should fail
338
+ otherHandler := func (invocation gbus.Invocation , message * gbus.BusMessage ) error {
339
+
340
+ otherHandlerCalled = true
341
+ return nil
342
+ }
343
+ svc1 := createNamedBusForTest (testSvc1 )
344
+ svc1 .SetGlobalRawMessageHandler (handler )
345
+ svc1 .HandleMessage (Command1 {}, otherHandler )
346
+ _ = svc1 .Start ()
347
+ defer assertBusShutdown (svc1 , t )
348
+
349
+ cmd1 := gbus .NewBusMessage (Command1 {})
350
+ _ = svc1 .Send (context .Background (), testSvc1 , cmd1 )
351
+
352
+ if otherHandlerCalled == true {
353
+ t .Fail ()
354
+ }
355
+
356
+ //delay test execution so to make sure the second handler is not called
357
+ time .Sleep (1500 * time .Millisecond )
358
+ rejected , _ := metrics .GetRejectedMessagesValue ()
359
+ if rejected != 1 {
360
+ t .Errorf ("rejected messages metric was expected to be 1 but was %f" , rejected )
361
+ }
362
+
363
+ if otherHandlerCalled {
364
+ t .Errorf ("other handler that was not expected to be called was called " )
365
+ }
366
+ }
367
+
323
368
func TestReturnDeadToQueue (t * testing.T ) {
324
369
325
370
var visited bool
0 commit comments