コード例 #1
0
            private void UnloadOnThread()
            {
                try
                {
                    if (_simulateUnloadError)
                    {
                        throw new CannotUnloadAppDomainException("Testing: simulated unload error");
                    }

                    if (_simulateUnloadTimeout)
                    {
                        while (true)
                        {
                            ;
                        }
                    }

                    AppDomain.Unload(_domain);
                }
                catch (Exception ex)
                {
                    // We assume that the tests did something bad and just leave
                    // the orphaned AppDomain "out there".
                    var msg = DomainDetailsBuilder.DetailsFor(_domain,
                                                              $"Exception encountered unloading application domain: {ex.Message}");

                    _unloadException = new NUnitEngineException(msg);
                    log.Error(msg);
                }
            }
コード例 #2
0
            public void Unload(TestPackage package)
            {
                _simulateUnloadError   = package.GetSetting(EnginePackageSettings.SimulateUnloadError, false);
                _simulateUnloadTimeout = package.GetSetting(EnginePackageSettings.SimulateUnloadTimeout, false);

                _unloadThread = new Thread(new ThreadStart(UnloadOnThread));
                _unloadThread.Start();

                var timeout = TimeSpan.FromSeconds(30);

                if (!_unloadThread.Join((int)timeout.TotalMilliseconds))
                {
                    var msg = DomainDetailsBuilder.DetailsFor(_domain,
                                                              $"Unable to unload application domain: unload thread timed out after {timeout.TotalSeconds} seconds.");

                    log.Error(msg);
                    Kill(_unloadThread);

                    throw new NUnitEngineUnloadException(msg);
                }

                if (_unloadException != null)
                {
                    throw new NUnitEngineUnloadException("Exception encountered unloading application domain", _unloadException);
                }
            }