示例#1
0
        public void Run_With_External_Thread()
        {
            TimerTester timed_test = new TimerTester("External thread test"); // need this for a subscriber for ticks.
            LazyTimer t1 = new LazyTimer(TENTH_OF_SEC);
            timed_test.Subscribe(t1);
            // Normally I would keep Run private. This is just for show.
            Thread worker = new Thread(new ThreadStart(t1.Run));
            worker.Start();
            Thread.Sleep(TWO_SECONDS);
            t1.Stop();
            worker.Join();

            Assert.True( timed_test.HasTirggered() );
            Assert.GreaterOrEqual(timed_test.GetTriggerCount(), 39); // we should have at least 2000 / 10 = 40

            Console.WriteLine("------------------Resetting---------------------"); // a visual

            timed_test.Reset(); // reset the test helper's count and triggered flag.

            worker = new Thread(new ThreadStart(t1.Run));
            t1.ResetTo(TEN_MILLISEC);
            worker.Start();
            Thread.Sleep(TWO_SECONDS);
            t1.Stop();
            worker.Join();

            Assert.True(timed_test.HasTirggered());

            // Was going to put a binominal
            Assert.GreaterOrEqual(timed_test.GetTriggerCount(), (TWO_SECONDS / TEN_MILLISEC)); // we should have at least 2000 / 10 = 400
        }
示例#2
0
        public void Check_NextRand_limits()
        {
            LazyTimer timer = new LazyTimer(TENTH_OF_SEC);
            int first = timer.NextTickInterval();
            Assert.AreNotEqual(first, timer.NextTickInterval());
            for (int i = 0; i < 2000; i++)
            {
                Assert.LessOrEqual(timer.NextTickInterval(), TENTH_OF_SEC);
                Assert.GreaterOrEqual(timer.NextTickInterval(), 0);

            }
        }
示例#3
0
        public void Internal_Thread_Start_Stop_test()
        {
            LazyTimer lazybones = new LazyTimer(ONE_SECOND);
            TimerTester evaluator = new TimerTester("Internal thread test"); // need this for a subscriber for ticks.
            evaluator.Subscribe(lazybones);

            Assert.IsFalse(evaluator.HasTirggered());

            // make sure our internal thread works.
            lazybones.Start();
            Thread.Sleep(ONE_SECOND);
            lazybones.Stop();

            Assert.IsTrue(evaluator.HasTirggered());
        }
示例#4
0
 public void Subscribe(LazyTimer timer)
 {
     timer.TickHandler += new LazyTimer.OnAdvanceTick(RecordEvent);
 }
示例#5
0
        public void Test_Multi_Subscribers()
        {
            LazyTimer lazybones = new LazyTimer(ONE_SECOND);
            TimerTester evaluator1 = new TimerTester("Subscriber 1");
            TimerTester evaluator2 = new TimerTester("Subscriber 2");
            evaluator1.Subscribe(lazybones);
            evaluator2.Subscribe(lazybones);

            Assert.IsFalse(evaluator1.HasTirggered());
            Assert.IsFalse(evaluator2.HasTirggered());

            // make sure our internal thread works.
            lazybones.Start();
            Thread.Sleep(ONE_SECOND);
            lazybones.Stop();

            Assert.IsTrue(evaluator1.HasTirggered());
            Assert.IsTrue(evaluator2.HasTirggered());
        }