public async Task GlobalErrorHandler_HandlerFails_NoInfiniteLoop() { ErrorTriggerProgram_GlobalCatchAllHandler instance = new ErrorTriggerProgram_GlobalCatchAllHandler(fail: true); JobHostConfiguration config = new JobHostConfiguration() { TypeLocator = new ExplicitTypeLocator(instance.GetType()), JobActivator = new ExplicitJobActivator(instance) }; config.UseCore(); config.AddService <IWebJobsExceptionHandler>(new TestExceptionHandler()); JobHost host = new JobHost(config); await host.StartAsync(); TestTraceWriter traceWriter = new TestTraceWriter(); config.Tracing.Tracers.Add(traceWriter); MethodInfo method = instance.GetType().GetMethod("Throw"); await CallSafe(host, method); Assert.Equal(1, instance.Errors.Count); TraceEvent error = instance.Errors.Single(); Assert.Equal("Exception while executing function: ErrorTriggerProgram_GlobalCatchAllHandler.Throw", error.Message); // make sure the error handler failure is still logged var events = traceWriter.Events; Assert.Equal(8, events.Count); Assert.StartsWith("Executing 'ErrorTriggerProgram_GlobalCatchAllHandler.Throw'", events[0].Message); Assert.StartsWith("Executing 'ErrorTriggerProgram_GlobalCatchAllHandler.ErrorHandler'", events[1].Message); Assert.StartsWith("Exception while executing function: ErrorTriggerProgram_GlobalCatchAllHandler.ErrorHandler", events[2].Message); Assert.Equal("Kaboom!", events[3].Exception.InnerException.Message); Assert.StartsWith("Executed 'ErrorTriggerProgram_GlobalCatchAllHandler.ErrorHandler' (Failed, ", events[3].Message); Assert.StartsWith(" Function had errors. See Azure WebJobs SDK dashboard for details.", events[4].Message); Assert.StartsWith("Exception while executing function: ErrorTriggerProgram_GlobalCatchAllHandler.Throw", events[5].Message); Assert.StartsWith("Executed 'ErrorTriggerProgram_GlobalCatchAllHandler.Throw' (Failed, ", events[6].Message); Assert.StartsWith(" Function had errors. See Azure WebJobs SDK dashboard for details.", events[7].Message); }
public async Task GlobalErrorHandler_CatchAll_InvokedAsExpected() { ErrorTriggerProgram_GlobalCatchAllHandler instance = new ErrorTriggerProgram_GlobalCatchAllHandler(); JobHostConfiguration config = new JobHostConfiguration() { TypeLocator = new ExplicitTypeLocator(instance.GetType()), JobActivator = new ExplicitJobActivator(instance) }; config.UseCore(); JobHost host = new JobHost(config); await host.StartAsync(); MethodInfo method = instance.GetType().GetMethod("Throw"); await CallSafe(host, method); Assert.NotNull(instance.TraceFilter); Assert.Equal("One or more WebJob errors have occurred.", instance.TraceFilter.Message); Assert.Equal(1, instance.TraceFilter.GetEvents().Count()); }