Пример #1
0
 public MyEventHandler(string name, MyRingBuffer ringBuffer, MyEventHandler dependency)
 {
     _name       = name;
     _cancel     = new CancellationTokenSource();
     _dependency = dependency;
     _ringBuffer = ringBuffer;
     Logs        = new List <string>();
     _workProc   = Task.Run(DoWork, _cancel.Token);
 }
Пример #2
0
        public async Task ShouldTestEventHandlerSynchronization()
        {
            var ringBuffer = new MyRingBuffer(32);

            var processDuration = 5000;

            //two consumers
            //  var expectedEventsCount = (processDuration / waituntilNextEvent) * 2;

            var handler1 = new MyEventHandler("a", ringBuffer, null);
            var handler2 = new MyEventHandler("b", ringBuffer, handler1);
            var handler3 = new MyEventHandler("c", ringBuffer, handler2);

            await Task.Delay(processDuration);

            handler1.Dispose();
            handler2.Dispose();
            handler3.Dispose();

            //Assert.Greater(handler2.Logs.Count(), expectedEventsCount * 0.75);
            //Assert.Greater(handler3.Logs.Count(), expectedEventsCount * 0.75);
        }