예제 #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 ...");
 }
예제 #3
0
 public void SetUp ()
 {
     sync1 = new Semaphore(0);
     sync2 = new Semaphore(0);
     serviceable = new MyService(sync1, sync2);
     serviceSupport = new ServiceSupport(serviceable);
 }