Exemplo n.º 1
0
        public void TestRestartNotified()
        {
            // prepare workAction call tracking
            var    callEvent  = new AutoResetEvent(false);
            Action workAction = () => callEvent.Set();

            // initialize worker
            using (var worker = new MockWorker(workAction))
            {
                // start worker
                worker.Start();

                // verify workAction has not been called
                var wasCalled = callEvent.WaitOne(10);
                Assert.IsFalse(wasCalled);

                // notify worker
                worker.NotifyWork();

                // verify workAction has been called
                wasCalled = callEvent.WaitOne(10);
                Assert.IsTrue(wasCalled);

                // stop worker
                worker.Stop();

                // wait for worker to idle
                worker.WaitForIdle();

                // notify worker again
                worker.NotifyWork();

                //TODO calling callEvent.WaitOne(10) cancels the notify and fails the test, i'm not sure why
                //TODO calling Thread.Sleep(10) instead of callEvent.WaitOne has the same effect
                // verify workAction has not been called
                wasCalled = callEvent.WaitOne(10);
                Assert.IsFalse(wasCalled);

                // start worker again, it has already been notified
                worker.Start();

                // verify workAction has been called
                wasCalled = callEvent.WaitOne(1000);
                Assert.IsTrue(wasCalled);
            }
        }
Exemplo n.º 2
0
        public void TestRestart()
        {
            // prepare workAction call tracking
            var    callEvent  = new AutoResetEvent(false);
            Action workAction = () => callEvent.Set();

            // initialize worker
            using (var worker = new MockWorker(workAction))
            {
                // start worker
                worker.Start();

                // verify workAction has not been called
                var wasCalled = callEvent.WaitOne(1000);
                Assert.IsFalse(wasCalled);

                // notify worker
                worker.NotifyWork();

                // verify workAction has been called
                wasCalled = callEvent.WaitOne(10);
                Assert.IsTrue(wasCalled);

                // stop worker
                worker.Stop();

                // wait for worker to idle
                worker.WaitForIdle();

                // verify workAction has not been called
                wasCalled = callEvent.WaitOne(10);
                Assert.IsFalse(wasCalled);

                // start worker again
                worker.Start();

                // notify worker
                worker.NotifyWork();

                // verify workAction has been called
                wasCalled = callEvent.WaitOne(10);
                Assert.IsTrue(wasCalled);
            }
        }