public void BTM_AfterBlockingShutdown_UnregistersFromHostEnvironment() { var mutex = new object(); IRegisteredObject registeredObject = null; using (ShimsContext.Create()) { ShimHostingEnvironment.BehaveAsNotImplemented(); ShimHostingEnvironment.RegisterObjectIRegisteredObject = obj => { lock (mutex) registeredObject = obj; }; ShimHostingEnvironment.UnregisterObjectIRegisteredObject = obj => { lock (mutex) { Assert.AreSame(registeredObject, obj); registeredObject = null; } }; var instance = new RegisteredTasks(); var mre = new ManualResetEvent(false); instance.Run(() => mre.WaitOne()); mre.Set(); registeredObject.Stop(true); lock (mutex) { Assert.IsNull(registeredObject); } } }
public void BTM_BlockingShutdown_WaitsForAsyncTaskToExit() { var mutex = new object(); IRegisteredObject registeredObject = null; using (ShimsContext.Create()) { ShimHostingEnvironment.BehaveAsNotImplemented(); ShimHostingEnvironment.RegisterObjectIRegisteredObject = obj => { lock (mutex) registeredObject = obj; }; ShimHostingEnvironment.UnregisterObjectIRegisteredObject = obj => { lock (mutex) { Assert.AreSame(registeredObject, obj); registeredObject = null; } }; var instance = new RegisteredTasks(); var tcs = new TaskCompletionSource <object>(); instance.Run(() => tcs.Task); var task = Task.Run(() => registeredObject.Stop(true)); Assert.IsFalse(task.Wait(300)); lock (mutex) Assert.IsNotNull(registeredObject); tcs.TrySetResult(null); } }
public void BTM_AfterShutdownRequest_AsyncTaskStillRunning_ShutdownIsSignaled() { using (ShimsContext.Create()) { ShimHostingEnvironment.BehaveAsNotImplemented(); IRegisteredObject registeredObject = null; ShimHostingEnvironment.RegisterObjectIRegisteredObject = obj => { registeredObject = obj; }; ShimHostingEnvironment.UnregisterObjectIRegisteredObject = _ => { }; var instance = new RegisteredTasks(); var tcs = new TaskCompletionSource <object>(); instance.Run(() => tcs.Task); registeredObject.Stop(false); Assert.IsTrue(instance.Shutdown.IsCancellationRequested); tcs.TrySetResult(null); } }
public void BTM_AfterShutdownRequest_SyncTaskStillRunning_ShutdownIsSignaled() { using (ShimsContext.Create()) { ShimHostingEnvironment.BehaveAsNotImplemented(); IRegisteredObject registeredObject = null; ShimHostingEnvironment.RegisterObjectIRegisteredObject = obj => { registeredObject = obj; }; ShimHostingEnvironment.UnregisterObjectIRegisteredObject = _ => { }; var instance = new RegisteredTasks(); var mre = new ManualResetEvent(false); instance.Run(() => mre.WaitOne()); registeredObject.Stop(false); Assert.IsTrue(instance.Shutdown.IsCancellationRequested); mre.Set(); } }
public void Shutdown() { if (_log != null && _log.IsDebugEnabled) { _log.Debug("Stopping HostManager."); } lock (SyncRoot) { _serverTimer.Enabled = false; try { AppDomain.CurrentDomain.UnhandledException -= new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); foreach (ApplicationInfo applicationInfo in ApplicationManager.GetApplicationManager().GetRunningApplications()) { IRegisteredObject registeredObject = ApplicationManager.GetApplicationManager().GetObject(applicationInfo.Id, typeof(FluorineRuntimeProxy)); if (registeredObject != null) { registeredObject.Stop(true); } } ApplicationManager.GetApplicationManager().ShutdownAll(); if (_log != null && _log.IsDebugEnabled) { _log.Debug("Stopped HostManager."); } } catch (Exception ex) { if (_log != null) { _log.Fatal("Failed to stop HostManager.", ex); } } } }