Beispiel #1
0
        public void TimerTestNotStarted(int duration, int iterations, int tolerance)
        {
            int count         = 0;
            var delayTimeInMs = duration * iterations * 1000 + tolerance;

            var timer = new AlternateTimer.Timer();

            timer.Elapsed += (s, t) => TimerCallBack(ref count, s, t);
            timer.Stop();

            Task.Delay(delayTimeInMs).Wait();

            Assert.AreEqual(0, count);
        }
Beispiel #2
0
        private async Task LaunchTimer(int duration, int iterations, int tolerance)
        {
            var count         = 0;
            var delayTimeInMs = duration * iterations * 1000 + tolerance;

            var timer = new AlternateTimer.Timer();

            timer.Elapsed += (s, t) => TimerCallBack(ref count, s, t);
            timer.Start(duration);

            await Task.Delay(delayTimeInMs);

            timer.Stop();

            Assert.AreEqual(iterations, count);
        }
Beispiel #3
0
        public void TimerStartOverwrittenTest(int duration, int overwrite, int iterations, int tolerance)
        {
            int count         = 0;
            var delayTimeInMs = duration * iterations * 1000 + tolerance;

            var timer = new AlternateTimer.Timer();

            timer.Elapsed += (s, t) => TimerCallBack(ref count, s, t);
            timer.Start(duration);
            timer.Start(overwrite);

            Task.Delay(delayTimeInMs).Wait();

            timer.Stop();

            var expected = delayTimeInMs / (overwrite * 1000);

            Assert.AreEqual(expected, count);
        }
Beispiel #4
0
        public static void RunTest(string testName, int seconds, int iterations)
        {
            async Task Function()
            {
                var timer = new AlternateTimer.Timer();

                timer.Elapsed += (s, e) => WriteToConsole(testName, s, e);
                Console.WriteLine($"{testName} Start time:   {DateTime.UtcNow:MM/dd/yyyy hh:mm:ss.fff tt}");

                timer.Start(seconds);

                Task.Delay(seconds * iterations * 1000 + 900).Wait();

                await Task.Run(() => timer.Stop());

                Console.WriteLine($"{testName} Stop time:    {DateTime.UtcNow:MM/dd/yyyy hh:mm:ss.fff tt}");
            }

            Task.Run(Function);
        }