Esempio n. 1
0
        protected override void Dispose(bool disposing)
        {
            // Disposal has to perform two actions, unloading the runner and
            // stopping the agent. Both must be tried even if one fails so
            // there can be up to two independent errors to be reported
            // through an NUnitEngineException. We do that by combining messages.
            if (!_disposed && disposing)
            {
                _disposed = true;

                Exception unloadException = null;

                try
                {
                    Unload();
                }
                catch (Exception ex)
                {
                    // Save and log the unload error
                    unloadException = ex;
                    log.Error(ExceptionHelper.BuildMessage(ex));
                    log.Error(ExceptionHelper.BuildMessageAndStackTrace(ex));
                }

                if (_agentLease != null)
                {
                    try
                    {
                        _agentLease.Dispose();
                    }
                    catch (NUnitEngineUnloadException ex) when(unloadException != null)
                    {
                        // Both kinds of errors, throw exception with combined message
                        throw new NUnitEngineUnloadException(ExceptionHelper.BuildMessage(unloadException) + Environment.NewLine + ex.Message);
                    }
                    finally
                    {
                        _agentLease = null;
                    }
                }

                if (unloadException != null) // Add message line indicating we managed to stop agent anyway
                {
                    throw new NUnitEngineUnloadException("Agent Process was terminated successfully after error.", unloadException);
                }
            }
        }
Esempio n. 2
0
        private void CreateAgentAndRunner()
        {
            if (_agentLease == null)
            {
                // Increase the timeout to give time to attach a debugger
                bool debug = TestPackage.GetSetting(EnginePackageSettings.DebugAgent, false) ||
                             TestPackage.GetSetting(EnginePackageSettings.PauseBeforeRun, false);

                _agentLease = _agency.GetAgent(TestPackage, debug ? DEBUG_TIMEOUT : NORMAL_TIMEOUT);

                if (_agentLease == null)
                {
                    throw new NUnitEngineException("Unable to acquire remote process agent");
                }
            }

            if (_remoteRunner == null)
            {
                _remoteRunner = _agentLease.CreateRunner(TestPackage);
            }
        }