public void ShouldInterruptDuringBusySpin() { const long expectedNumberMessages = 10; FillRingBuffer(expectedNumberMessages); var signal = new CountdownEvent(3); var sequence1 = new CountDownEventSequence(8L, signal); var sequence2 = new CountDownEventSequence(8L, signal); var sequence3 = new CountDownEventSequence(8L, signal); _eventProcessorMock1.Setup(x => x.Sequence).Returns(sequence1); _eventProcessorMock2.Setup(x => x.Sequence).Returns(sequence2); _eventProcessorMock3.Setup(x => x.Sequence).Returns(sequence3); var sequenceBarrier = _ringBuffer.NewBarrier(Util.GetSequencesFor(_eventProcessorMock1.Object, _eventProcessorMock2.Object, _eventProcessorMock3.Object)); var alerted = false; var t = Task.Factory.StartNew(() => { try { sequenceBarrier.WaitFor(expectedNumberMessages - 1); } catch (AlertException) { alerted = true; } }); signal.Wait(TimeSpan.FromSeconds(3)); sequenceBarrier.Alert(); t.Wait(); Assert.That(alerted, Is.True, "Thread was not interrupted"); }
public void ShouldInterruptDuringBusySpin() { const long expectedNumberMessages = 10; FillRingBuffer(expectedNumberMessages); var signal = new CountdownEvent(3); var sequence1 = new CountDownEventSequence(8L, signal); var sequence2 = new CountDownEventSequence(8L, signal); var sequence3 = new CountDownEventSequence(8L, signal); var sequenceBarrier = _ringBuffer.NewBarrier(sequence1, sequence2, sequence3); var alerted = false; var t = Task.Run(() => { try { sequenceBarrier.WaitFor(expectedNumberMessages - 1); } catch (AlertException) { alerted = true; } }); signal.Wait(TimeSpan.FromSeconds(3)); sequenceBarrier.Alert(); t.Wait(); Assert.That(alerted, Is.True, "Thread was not interrupted"); }