@@ -315,18 +315,62 @@ Task ProcessMessage(ProcessMessageEventArgs args)
315
315
316
316
Task ExceptionHandler ( ProcessErrorEventArgs args )
317
317
{
318
+ if ( args . ErrorSource == ServiceBusErrorSource . ProcessMessageCallback )
319
+ {
320
+ throw new Exception ( ) ;
321
+ }
322
+
323
+ return Task . CompletedTask ;
324
+ }
325
+
326
+ processor . ProcessMessageAsync += ProcessMessage ;
327
+ processor . ProcessErrorAsync += ExceptionHandler ;
328
+
329
+ await processor . StartProcessingAsync ( ) ;
330
+ await tcs . Task ;
331
+ await processor . StopProcessingAsync ( ) ;
332
+ _listener . SingleEventById ( ServiceBusEventSource . ProcessorMessageHandlerStartEvent , args => args . Payload . Contains ( processor . Identifier ) ) ;
333
+ _listener . SingleEventById ( ServiceBusEventSource . ProcessorMessageHandlerExceptionEvent , args => args . Payload . Contains ( processor . Identifier ) ) ;
334
+ _listener . SingleEventById ( ServiceBusEventSource . ProcessorErrorHandlerThrewExceptionEvent , args => args . Payload . Contains ( processor . Identifier ) ) ;
335
+ }
336
+ }
337
+
338
+ [ Test ]
339
+ public async Task LogsSessionProcessorExceptionEvent ( )
340
+ {
341
+ await using ( var scope = await ServiceBusScope . CreateWithQueue ( enablePartitioning : false , enableSession : true ) )
342
+ {
343
+ await using var client = CreateClient ( ) ;
344
+ var sender = client . CreateSender ( scope . QueueName ) ;
345
+ await sender . SendMessageAsync ( ServiceBusTestUtilities . GetMessage ( "sessionId" ) ) ;
346
+ await using var processor = client . CreateSessionProcessor ( scope . QueueName ) ;
347
+ var tcs = new TaskCompletionSource < bool > ( ) ;
348
+
349
+ Task ProcessMessage ( ProcessSessionMessageEventArgs args )
350
+ {
351
+ tcs . SetResult ( true ) ;
318
352
throw new Exception ( ) ;
319
353
}
320
354
355
+ Task ExceptionHandler ( ProcessErrorEventArgs args )
356
+ {
357
+ if ( args . ErrorSource == ServiceBusErrorSource . ProcessMessageCallback )
358
+ {
359
+ throw new Exception ( ) ;
360
+ }
361
+
362
+ return Task . CompletedTask ;
363
+ }
364
+
321
365
processor . ProcessMessageAsync += ProcessMessage ;
322
366
processor . ProcessErrorAsync += ExceptionHandler ;
323
367
324
368
await processor . StartProcessingAsync ( ) ;
325
369
await tcs . Task ;
326
370
await processor . StopProcessingAsync ( ) ;
327
- _listener . SingleEventById ( ServiceBusEventSource . ProcessorMessageHandlerStartEvent ) ;
328
- _listener . SingleEventById ( ServiceBusEventSource . ProcessorMessageHandlerExceptionEvent ) ;
329
- _listener . SingleEventById ( ServiceBusEventSource . ProcessorErrorHandlerThrewExceptionEvent ) ;
371
+ _listener . SingleEventById ( ServiceBusEventSource . ProcessorMessageHandlerStartEvent , args => args . Payload . Contains ( processor . Identifier ) ) ;
372
+ _listener . SingleEventById ( ServiceBusEventSource . ProcessorMessageHandlerExceptionEvent , args => args . Payload . Contains ( processor . Identifier ) ) ;
373
+ _listener . SingleEventById ( ServiceBusEventSource . ProcessorErrorHandlerThrewExceptionEvent , args => args . Payload . Contains ( processor . Identifier ) ) ;
330
374
}
331
375
}
332
376
@@ -366,7 +410,7 @@ public async Task LogsProcessorClientClosedExceptionEvent()
366
410
await Task . Delay ( 500 , cancellationSource . Token ) ;
367
411
}
368
412
369
- _listener . SingleEventById ( ServiceBusEventSource . ProcessorClientClosedExceptionEvent ) ;
413
+ _listener . SingleEventById ( ServiceBusEventSource . ProcessorClientClosedExceptionEvent , args => args . Payload . Contains ( processor . Identifier ) ) ;
370
414
}
371
415
}
372
416
@@ -375,22 +419,26 @@ public async Task DoesNotLogAcceptSessionTimeoutAsError()
375
419
{
376
420
await using ( var scope = await ServiceBusScope . CreateWithQueue ( enablePartitioning : false , enableSession : true ) )
377
421
{
378
- await using var client = CreateNoRetryClient ( 5 ) ;
422
+ await using var client = CreateClient ( tryTimeout : 5 , maxRetries : 1 ) ;
379
423
await using var processor = client . CreateSessionProcessor ( scope . QueueName ) ;
380
424
381
425
processor . ProcessMessageAsync += args => Task . CompletedTask ;
382
426
processor . ProcessErrorAsync += args => Task . CompletedTask ;
383
427
384
428
await processor . StartProcessingAsync ( ) ;
385
429
386
- // wait twice as long as the try timeout to ensure that the Accept session will timeout
387
- await Task . Delay ( TimeSpan . FromSeconds ( 10 ) ) ;
430
+ // wait long enough to ensure that the Accept session will timeout accounting for retries
431
+ await Task . Delay ( TimeSpan . FromSeconds ( 20 ) ) ;
388
432
389
433
await processor . StopProcessingAsync ( ) ;
390
434
391
- Assert . False ( _listener . EventsById ( ServiceBusEventSource . CreateReceiveLinkExceptionEvent ) . Any ( ) ) ;
392
- Assert . False ( _listener . EventsById ( ServiceBusEventSource . ClientCreateExceptionEvent ) . Any ( ) ) ;
393
- Assert . True ( _listener . EventsById ( ServiceBusEventSource . ProcessorAcceptSessionTimeoutEvent ) . Any ( e => e . Level == EventLevel . Verbose ) ) ;
435
+ bool ContainsEntityPath ( EventWrittenEventArgs args ) => args . Payload . Contains ( processor . EntityPath ) ;
436
+
437
+ Assert . False ( _listener . EventsById ( ServiceBusEventSource . CreateReceiveLinkExceptionEvent ) . Any ( ContainsEntityPath ) ) ;
438
+ Assert . False ( _listener . EventsById ( ServiceBusEventSource . ClientCreateExceptionEvent ) . Any ( ContainsEntityPath ) ) ;
439
+ Assert . True ( _listener . EventsById ( ServiceBusEventSource . ProcessorAcceptSessionTimeoutEvent ) . Any ( e => e . Level == EventLevel . Verbose && ContainsEntityPath ( e ) ) ) ;
440
+ Assert . True ( _listener . EventsById ( ServiceBusEventSource . RunOperationExceptionVerboseEvent ) . Any ( e => e . Level == EventLevel . Verbose ) ) ;
441
+ Assert . False ( _listener . EventsById ( ServiceBusEventSource . RunOperationExceptionEvent ) . Any ( ContainsEntityPath ) ) ;
394
442
}
395
443
}
396
444
@@ -413,8 +461,9 @@ public async Task DoesNotLogStoppingAcceptSessionCanceledAsError()
413
461
await processor . StopProcessingAsync ( ) ;
414
462
415
463
Assert . False ( _listener . EventsById ( ServiceBusEventSource . CreateReceiveLinkExceptionEvent ) . Any ( ) ) ;
416
- Assert . False ( _listener . EventsById ( ServiceBusEventSource . ClientCreateExceptionEvent ) . Any ( ) ) ;
417
- Assert . True ( _listener . EventsById ( ServiceBusEventSource . ProcessorStoppingAcceptSessionCanceledEvent ) . Any ( e => e . Level == EventLevel . Verbose ) ) ;
464
+ Assert . False ( _listener . EventsById ( ServiceBusEventSource . ClientCreateExceptionEvent ) . Any ( e => e . Payload . Contains ( processor . EntityPath ) ) ) ;
465
+ Assert . True ( _listener . EventsById ( ServiceBusEventSource . ProcessorStoppingAcceptSessionCanceledEvent )
466
+ . Any ( e => e . Level == EventLevel . Verbose ) ) ;
418
467
}
419
468
}
420
469
@@ -437,7 +486,7 @@ public async Task StoppingProcessorDoesNotLogTaskCanceledExceptions()
437
486
await processor . StopProcessingAsync ( ) ;
438
487
439
488
Assert . False ( _listener . EventsById ( ServiceBusEventSource . CreateReceiveLinkExceptionEvent ) . Any ( ) ) ;
440
- Assert . False ( _listener . EventsById ( ServiceBusEventSource . ClientCreateExceptionEvent ) . Any ( ) ) ;
489
+ Assert . False ( _listener . EventsById ( ServiceBusEventSource . ClientCreateExceptionEvent ) . Any ( e => e . Payload . Contains ( processor . EntityPath ) ) ) ;
441
490
Assert . True ( _listener . EventsById ( ServiceBusEventSource . ProcessorStoppingReceiveCanceledEvent ) . Any ( ) ) ;
442
491
}
443
492
}
@@ -467,7 +516,7 @@ public async Task StoppingSessionProcessorDoesNotLogTaskCanceledExceptions()
467
516
await processor . StopProcessingAsync ( ) ;
468
517
469
518
Assert . False ( _listener . EventsById ( ServiceBusEventSource . CreateReceiveLinkExceptionEvent ) . Any ( ) ) ;
470
- Assert . False ( _listener . EventsById ( ServiceBusEventSource . ClientCreateExceptionEvent ) . Any ( ) ) ;
519
+ Assert . False ( _listener . EventsById ( ServiceBusEventSource . ClientCreateExceptionEvent ) . Any ( e => e . Payload . Contains ( processor . EntityPath ) ) ) ;
471
520
Assert . True ( _listener . EventsById ( ServiceBusEventSource . ProcessorStoppingReceiveCanceledEvent ) . Any ( ) ) ;
472
521
}
473
522
}
0 commit comments