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()); }
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 }
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()); }