public void ShouldCallExceptionHandlerOnTimeoutException() { var waitStrategy = new TimeoutBlockingWaitStrategy(TimeSpan.FromMilliseconds(1)); var ringBuffer = new ValueRingBuffer <StubValueEvent>(() => new StubValueEvent(-1), new SingleProducerSequencer(16, waitStrategy)); var sequenceBarrier = ringBuffer.NewBarrier(); var exceptionSignal = new CountdownEvent(1); var exceptionHandler = new TestValueExceptionHandler <StubValueEvent>(x => exceptionSignal.Signal()); var eventHandler = new TestValueEventHandler <StubValueEvent> { OnTimeoutAction = TestException.ThrowOnce() }; var eventProcessor = CreateEventProcessor(ringBuffer, sequenceBarrier, eventHandler); ringBuffer.AddGatingSequences(eventProcessor.Sequence); eventProcessor.SetExceptionHandler(exceptionHandler); var task = eventProcessor.Start(); Assert.IsTrue(exceptionSignal.Wait(TimeSpan.FromSeconds(2))); Assert.AreEqual(0, exceptionHandler.EventExceptionCount); Assert.AreEqual(1, exceptionHandler.TimeoutExceptionCount); eventProcessor.Halt(); Assert.IsTrue(task.Wait(TimeSpan.FromSeconds(2))); }
public void ShouldTimeoutWaitFor() { var sequenceBarrier = new DummySequenceBarrier(); var theTimeout = TimeSpan.FromMilliseconds(500); TimeoutBlockingWaitStrategy waitStrategy = new TimeoutBlockingWaitStrategy(theTimeout); Sequence cursor = new Sequence(5); Sequence dependent = cursor; var t0 = DateTime.UtcNow; try { waitStrategy.WaitFor(6, cursor, dependent, sequenceBarrier); throw new ApplicationException("TimeoutException should have been thrown"); } catch (TimeoutException e) { } var t1 = DateTime.UtcNow; var timeWaiting = t1 - t0; Assert.That(timeWaiting, Is.GreaterThanOrEqualTo(theTimeout)); }
public void ShouldTimeoutWaitFor() { var sequenceBarrier = new Mock<ISequenceBarrier>(); var theTimeout = TimeSpan.FromMilliseconds(500); TimeoutBlockingWaitStrategy waitStrategy = new TimeoutBlockingWaitStrategy(theTimeout); Sequence cursor = new Sequence(5); Sequence dependent = cursor; var t0 = DateTime.UtcNow; try { waitStrategy.WaitFor(6, cursor, dependent, sequenceBarrier.Object); throw new ApplicationException("TimeoutException should have been thrown"); } catch (TimeoutException e) { } var t1 = DateTime.UtcNow; var timeWaiting = t1 - t0; sequenceBarrier.Verify(x => x.CheckAlert()); Assert.That(timeWaiting, Is.GreaterThanOrEqualTo(theTimeout)); }
public void ShouldTimeoutWaitFor() { var sequenceBarrier = new DummySequenceBarrier(); var theTimeout = TimeSpan.FromMilliseconds(500); var waitStrategy = new TimeoutBlockingWaitStrategy(theTimeout); var cursor = new Sequence(5); var dependent = cursor; var stopwatch = Stopwatch.StartNew(); Assert.Throws <TimeoutException>(() => waitStrategy.WaitFor(6, cursor, dependent, sequenceBarrier)); stopwatch.Stop(); // Required to make the test pass on azure pipelines. var tolerance = TimeSpan.FromMilliseconds(25); Assert.That(stopwatch.Elapsed, Is.GreaterThanOrEqualTo(theTimeout - tolerance)); }
public void ShouldCallOnTimeout() { var waitStrategy = new TimeoutBlockingWaitStrategy(TimeSpan.FromMilliseconds(1)); var ringBuffer = new ValueRingBuffer <StubValueEvent>(() => new StubValueEvent(-1), new SingleProducerSequencer(16, waitStrategy)); var sequenceBarrier = ringBuffer.NewBarrier(); var onTimeoutSignal = new ManualResetEvent(false); var eventHandler = new TestValueEventHandler <StubValueEvent> { OnTimeoutAction = () => onTimeoutSignal.Set() }; var eventProcessor = CreateEventProcessor(ringBuffer, sequenceBarrier, eventHandler); ringBuffer.AddGatingSequences(eventProcessor.Sequence); var task = eventProcessor.Start(); Assert.IsTrue(onTimeoutSignal.WaitOne(TimeSpan.FromSeconds(2))); eventProcessor.Halt(); Assert.IsTrue(task.Wait(TimeSpan.FromSeconds(2))); }