示例#1
0
        public void ShouldHaveHandlersInSync()
        {
            // we test here whether handler executed by the slower clock entry
            // always "sees" value of the faster one as ten times its own value
            var clockSource = new BaseClockSource();

            Action firstHandler = () =>
            {
            };

            var values = new List <ulong>();

            clockSource.AddClockEntry(new ClockEntry(10000, 10, firstHandler, null, String.Empty));
            clockSource.AddClockEntry(new ClockEntry(10, 1, () => values.Add(clockSource.GetClockEntry(firstHandler).Value), null, String.Empty));

            clockSource.Advance(TimeInterval.FromSeconds(9), true);
            clockSource.Advance(TimeInterval.FromSeconds(8), true);
            clockSource.Advance(TimeInterval.FromSeconds(20), true);

            CollectionAssert.AreEqual(new [] { 100, 200, 300 }, values);
        }
示例#2
0
        public void ShouldHaveHandlersInSync()
        {
            // we test here whether handler executed by the slower clock entry
            // always "sees" value of the faster one as ten times its own value
            var clockSource = new BaseClockSource();

            Action firstHandler = () =>
            {
            };

            var values = new List <ulong>();

            // clock entry with ratio -10 is 10 times slower than the one with 1
            clockSource.AddClockEntry(new ClockEntry(10000, 1, firstHandler));
            clockSource.AddClockEntry(new ClockEntry(1, -10, () => values.Add(clockSource.GetClockEntry(firstHandler).Value)));

            clockSource.Advance(TimeInterval.FromTicks(9), true);
            clockSource.Advance(TimeInterval.FromTicks(8), true);
            clockSource.Advance(TimeInterval.FromTicks(20), true);

            CollectionAssert.AreEqual(new [] { 10, 20, 30 }, values);
        }
示例#3
0
        public void ShouldObserveShorterPeriodClockAfterAdd()
        {
            var        clockSource = new BaseClockSource();
            var        counterA    = 0;
            var        counterB    = 0;
            Action     handlerA    = () => counterA++;
            Action     handlerB    = () => counterB++;
            ClockEntry entryA      = new ClockEntry(1000, 1, handlerA, null, String.Empty)
            {
                Value = 0
            };
            ClockEntry entryB = new ClockEntry(100, 1, handlerB, null, String.Empty)
            {
                Value = 0
            };

            clockSource.AddClockEntry(entryA);
            clockSource.Advance(TimeInterval.FromSeconds(500));
            clockSource.AddClockEntry(entryB);
            entryA = clockSource.GetClockEntry(handlerA);
            entryB = clockSource.GetClockEntry(handlerB);
            Assert.AreEqual(entryA.Value, 500);
            Assert.AreEqual(entryA.Period, 1000);
            Assert.AreEqual(entryB.Value, 0);
            Assert.AreEqual(entryB.Period, 100);

            clockSource.Advance(TimeInterval.FromSeconds(50));
            entryA = clockSource.GetClockEntry(handlerA);
            entryB = clockSource.GetClockEntry(handlerB);
            Assert.AreEqual(counterA, 0);
            Assert.AreEqual(counterB, 0);
            Assert.AreEqual(entryA.Value, 550);
            Assert.AreEqual(entryA.Period, 1000);
            Assert.AreEqual(entryB.Value, 50);
            Assert.AreEqual(entryB.Period, 100);

            clockSource.Advance(TimeInterval.FromSeconds(50));
            entryA = clockSource.GetClockEntry(handlerA);
            entryB = clockSource.GetClockEntry(handlerB);
            Assert.AreEqual(counterA, 0);
            Assert.AreEqual(counterB, 1);
            Assert.AreEqual(entryA.Value, 600);
            Assert.AreEqual(entryA.Period, 1000);
            Assert.AreEqual(entryB.Value, 0);
            Assert.AreEqual(entryB.Period, 100);
        }