Пример #1
0
        public void WaitForStartedBeforeStopping()
        {
            MyService serviceable = new MyService(sync1, sync2);
            ISync     starting    = new Latch();
            ISync     started     = new Latch();
            BlockWhileStartingExecutor executor =
                new BlockWhileStartingExecutor(starting, started);
            MyServiceSupport support = new MyServiceSupport(executor, serviceable);

            executor.ServiceSupport = support;
            Thread startThread = new Thread(new ThreadStart(executor.Start));

            startThread.Name = "start";
            startThread.Start();
            Log("start thread started");
            Latch          stopping   = new Latch();
            Latch          stopped    = new Latch();
            StoppingHelper helper     = new StoppingHelper(support, stopping, stopped);
            Thread         stopThread = new Thread(new ThreadStart(helper.Stop));

            stopThread.Name = "stop";
            stopThread.Start();
            Log("stop thread started: waiting for stopping ...");
            stopping.Acquire();
            Log("stopping in progress ...");
            Assert.IsFalse(executor.wasStarted);
            Assert.IsFalse(helper.wasStopped, "helper could stop before expected");
            Log("allow to start ...");
            starting.Release();
            Log("waiting for started ...");
            started.Acquire();
            Assert.IsTrue(executor.wasStarted);
            stopped.Acquire();
            Log("waiting for stop ...");
            Assert.IsTrue(helper.wasStopped);
            Log("stopped ...");
        }
Пример #2
0
 public void WaitForStartedBeforeStopping()
 {
     MyService serviceable = new MyService(sync1, sync2);
     ISync starting = new Latch();
     ISync started = new Latch();
     BlockWhileStartingExecutor executor = 
         new BlockWhileStartingExecutor(starting, started);
     MyServiceSupport support = new MyServiceSupport(executor, serviceable);
     executor.ServiceSupport = support;
     Thread startThread = new Thread(new ThreadStart(executor.Start));
     startThread.Name = "start";
     startThread.Start();
     Log ("start thread started");
     Latch stopping = new Latch();
     Latch stopped = new Latch();
     StoppingHelper helper = new StoppingHelper(support, stopping, stopped);
     Thread stopThread = new Thread(new ThreadStart(helper.Stop));
     stopThread.Name = "stop";
     stopThread.Start();
     Log ("stop thread started: waiting for stopping ...");
     stopping.Acquire();
     Log ("stopping in progress ...");
     Assert.IsFalse(executor.wasStarted);
     Assert.IsFalse(helper.wasStopped, "helper could stop before expected");
     Log ("allow to start ...");
     starting.Release();
     Log ("waiting for started ...");
     started.Acquire();
     Assert.IsTrue(executor.wasStarted);
     stopped.Acquire();
     Log ("waiting for stop ...");
     Assert.IsTrue(helper.wasStopped);
     Log ("stopped ...");
 }