public void ShouldCallExceptionHandlerOnTimeoutException() { var waitStrategy = new AsyncWaitStrategy(TimeSpan.FromMilliseconds(1)); var ringBuffer = new RingBuffer <StubEvent>(() => new StubEvent(-1), new SingleProducerSequencer(16, waitStrategy)); var sequenceBarrier = ringBuffer.NewAsyncBarrier(); var exception = new TaskCompletionSource <Exception>(); var exceptionHandler = new TestExceptionHandler <StubEvent>(x => exception.TrySetResult(x.ex)); var eventHandler = new TestAsyncBatchEventHandler <StubEvent> { OnTimeoutAction = TestException.ThrowOnce() }; var eventProcessor = CreateEventProcessor(ringBuffer, sequenceBarrier, eventHandler); ringBuffer.AddGatingSequences(eventProcessor.Sequence); eventProcessor.SetExceptionHandler(exceptionHandler); var task = eventProcessor.Start(); Assert.IsTrue(exception.Task.Wait(TimeSpan.FromSeconds(2))); Assert.AreEqual(0, exceptionHandler.EventExceptionCount); Assert.AreEqual(1, exceptionHandler.TimeoutExceptionCount); Assert.AreEqual(0, exceptionHandler.BatchExceptionCount); eventProcessor.Halt(); Assert.IsTrue(task.Wait(TimeSpan.FromSeconds(2))); }
public AsyncChainEndToEndTests(TestFixture fixture) { _fixture = fixture; _resolver = new RandomNameResolver(); _hostConfig = new JobHostConfiguration() { NameResolver = _resolver, TypeLocator = new FakeTypeLocator(typeof(AsyncChainEndToEndTests)) }; _defaultExceptionHandler = new TestExceptionHandler(); _hostConfig.AddService <IWebJobsExceptionHandler>(_defaultExceptionHandler); _hostConfig.Queues.MaxPollingInterval = TimeSpan.FromSeconds(2); _storageAccount = fixture.StorageAccount; _timeoutJobDelay = TimeSpan.FromMinutes(5); ILoggerFactory loggerFactory = new LoggerFactory(); loggerFactory.AddProvider(_loggerProvider); _hostConfig.LoggerFactory = loggerFactory; _hostConfig.Aggregator.IsEnabled = false; // makes validation easier CloudQueueClient queueClient = _storageAccount.CreateCloudQueueClient(); string queueName = _resolver.ResolveInString(TestQueueName); _testQueue = queueClient.GetQueueReference(queueName); if (!_testQueue.CreateIfNotExistsAsync().Result) { _testQueue.ClearAsync().Wait(); } }
public async Task Timeout_TimeoutExpires_Cancels() { var exceptionHandler = new TestExceptionHandler(); await RunTimeoutTest(exceptionHandler, typeof(TaskCanceledException), "TimeoutJob"); Assert.Empty(exceptionHandler.UnhandledExceptionInfos); Assert.Empty(exceptionHandler.TimeoutExceptionInfos); }
public void ShouldCallExceptionHandlerOnMultipleUncaughtException() { var processingSignal = new AutoResetEvent(false); var exceptionHandler = new TestExceptionHandler <StubEvent>(x => processingSignal.Set()); var eventHandler = new TestAsyncBatchEventHandler <StubEvent>(x => { if (x.Value == 1) { throw new Exception(); } processingSignal.Set(); }); var eventProcessor = CreateEventProcessor(_ringBuffer, _sequenceBarrier, eventHandler); _ringBuffer.AddGatingSequences(eventProcessor.Sequence); eventProcessor.SetExceptionHandler(exceptionHandler); var task = eventProcessor.Start(); _ringBuffer.PublishStubEvent(0); Assert.IsTrue(processingSignal.WaitOne(TimeSpan.FromSeconds(2))); Assert.AreEqual(0, exceptionHandler.EventExceptionCount); Assert.AreEqual(0, exceptionHandler.TimeoutExceptionCount); Assert.AreEqual(0, exceptionHandler.BatchExceptionCount); _ringBuffer.PublishStubEvent(1); Assert.IsTrue(processingSignal.WaitOne(TimeSpan.FromSeconds(2))); Assert.AreEqual(0, exceptionHandler.EventExceptionCount); Assert.AreEqual(0, exceptionHandler.TimeoutExceptionCount); Assert.AreEqual(1, exceptionHandler.BatchExceptionCount); _ringBuffer.PublishStubEvent(0); Assert.IsTrue(processingSignal.WaitOne(TimeSpan.FromSeconds(2))); Assert.AreEqual(0, exceptionHandler.EventExceptionCount); Assert.AreEqual(0, exceptionHandler.TimeoutExceptionCount); Assert.AreEqual(1, exceptionHandler.BatchExceptionCount); _ringBuffer.PublishStubEvent(1); Assert.IsTrue(processingSignal.WaitOne(TimeSpan.FromSeconds(2))); Assert.AreEqual(0, exceptionHandler.EventExceptionCount); Assert.AreEqual(0, exceptionHandler.TimeoutExceptionCount); Assert.AreEqual(2, exceptionHandler.BatchExceptionCount); _ringBuffer.PublishStubEvent(0); Assert.IsTrue(processingSignal.WaitOne(TimeSpan.FromSeconds(2))); Assert.AreEqual(0, exceptionHandler.EventExceptionCount); Assert.AreEqual(0, exceptionHandler.TimeoutExceptionCount); Assert.AreEqual(2, exceptionHandler.BatchExceptionCount); eventProcessor.Halt(); Assert.IsTrue(task.Wait(TimeSpan.FromSeconds(2))); }
public async Task TimeoutWithThrow_NoCancellationToken_CancelsAndThrows() { var exceptionHandler = new TestExceptionHandler(); await RunTimeoutTest(exceptionHandler, typeof(FunctionTimeoutException), "TimeoutJob_Throw_NoToken"); var exception = exceptionHandler.TimeoutExceptionInfos.Single().SourceException; Assert.IsType <FunctionTimeoutException>(exception); Assert.Empty(exceptionHandler.UnhandledExceptionInfos); }
public void ShouldCallExceptionHandlerOnUncaughtException() { var exceptionSignal = new CountdownEvent(1); var exceptionHandler = new TestExceptionHandler <StubEvent>(x => exceptionSignal.Signal()); var eventHandler = new TestEventHandler <StubEvent>(x => throw new NullReferenceException()); var batchEventProcessor = CreateBatchEventProcessor(_ringBuffer, _sequenceBarrier, eventHandler); _ringBuffer.AddGatingSequences(batchEventProcessor.Sequence); batchEventProcessor.SetExceptionHandler(exceptionHandler); var task = Task.Run(() => batchEventProcessor.Run()); _ringBuffer.Publish(_ringBuffer.Next()); Assert.IsTrue(exceptionSignal.Wait(TimeSpan.FromSeconds(2))); batchEventProcessor.Halt(); Assert.IsTrue(task.Wait(500)); }
public void ShouldCallExceptionHandlerOnUncaughtException() { var exceptionSignal = new CountdownEvent(1); var exceptionHandler = new TestExceptionHandler <StubEvent>(x => exceptionSignal.Signal()); var eventHandler = new TestAsyncBatchEventHandler <StubEvent>(x => throw new NullReferenceException()); var eventProcessor = CreateEventProcessor(_ringBuffer, _sequenceBarrier, eventHandler); _ringBuffer.AddGatingSequences(eventProcessor.Sequence); eventProcessor.SetExceptionHandler(exceptionHandler); var task = eventProcessor.Start(); _ringBuffer.PublishStubEvent(0); Assert.IsTrue(exceptionSignal.Wait(TimeSpan.FromSeconds(2))); Assert.AreEqual(0, exceptionHandler.EventExceptionCount); Assert.AreEqual(0, exceptionHandler.TimeoutExceptionCount); Assert.AreEqual(1, exceptionHandler.BatchExceptionCount); eventProcessor.Halt(); Assert.IsTrue(task.Wait(TimeSpan.FromSeconds(2))); }