public override void Dispose() { if (_agent != null) { log.Info("Stopping remote agent"); _agent.Stop(); _agent = null; } }
protected override void Dispose(bool disposing) { base.Dispose(disposing); if (disposing && _agent != null) { log.Info("Stopping remote agent"); _agent.Stop(); _agent = null; } }
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; string unloadError = null; try { Unload(); } catch (Exception ex) { // Save and log the unload error unloadError = ex.Message; log.Error(unloadError); } if (_agent != null) { try { log.Debug("Stopping remote agent"); _agent.Stop(); _agent = null; } catch (Exception e) { string stopError = string.Format("Failed to stop the remote agent. {0}", e.Message); log.Error(stopError); _agent = null; // Stop error with no unload error, just rethrow if (unloadError == null) { throw; } // Both kinds of errors, throw exception with combined message throw new NUnitEngineException(unloadError + Environment.NewLine + stopError); } } if (unloadError != null) // Add message line indicating we managed to stop agent anyway { throw (new NUnitEngineException(unloadError + "\nAgent Process was terminated successfully after error.")); } } }
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 (_agent != null && _agency.IsAgentProcessActive(_agent.Id, out _)) { try { log.Debug("Stopping remote agent"); _agent.Stop(); } 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 { _agent = 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); } } }
protected override void Dispose(bool disposing) { base.Dispose(disposing); try { if (disposing && _agent != null) { log.Debug("Stopping remote agent"); _agent.Stop(); _agent = null; } } catch (Exception e) { log.Error("Failed to stop the remote agent. {0}", e.Message); _agent = null; } }
private void Release(Guid agentId, ITestAgent agent) { if (_agentStore.IsAgentProcessActive(agentId, out var process)) { try { log.Debug("Stopping remote agent"); agent.Stop(); } catch (SocketException ex) { int?exitCode; try { exitCode = process.ExitCode; } catch (NotSupportedException) { exitCode = null; } if (exitCode == 0) { log.Warning("Agent connection was forcibly closed. Exit code was 0, so agent shutdown OK"); } else { var stopError = $"Agent connection was forcibly closed. Exit code was {exitCode?.ToString() ?? "unknown"}. {Environment.NewLine}{ExceptionHelper.BuildMessageAndStackTrace(ex)}"; log.Error(stopError); throw new NUnitEngineUnloadException(stopError, ex); } } catch (Exception ex) { var stopError = "Failed to stop the remote agent." + Environment.NewLine + ExceptionHelper.BuildMessageAndStackTrace(ex); log.Error(stopError); throw new NUnitEngineUnloadException(stopError, ex); } } }
/// <summary> /// Releases the test agent back to the supplier, which provided it. /// </summary> /// <param name="agent">An agent previously provided by a call to GetAgent.</param> /// <exception cref="InvalidOperationException"> /// If agent was never provided by the factory or was previously released. /// </exception> /// <remarks> /// Disposing an agent also releases it. However, this should not /// normally be done by the client, but by the source that created /// the agent in the first place. /// </remarks> public void ReleaseAgent(ITestAgent agent) { Process process; if (_agentStore.IsAgentActive(agent.Id, out process)) { try { log.Debug("Stopping remote agent"); agent.Stop(); } catch (SocketException se) { int exitCode; try { exitCode = process.ExitCode; } catch (NotSupportedException) { exitCode = -17; } if (exitCode == 0) { log.Warning("Agent connection was forcibly closed. Exit code was 0, so agent shutdown OK"); } else { var stopError = $"Agent connection was forcibly closed. Exit code was {exitCode}. {Environment.NewLine}{ExceptionHelper.BuildMessageAndStackTrace(se)}"; log.Error(stopError); throw; } } }
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 (_agent != null && _agency.IsAgentRunning(_agent.Id)) { try { log.Debug("Stopping remote agent"); _agent.Stop(); } catch (SocketException se) { var exitCode = _agency.GetAgentExitCode(_agent.Id); if (exitCode.HasValue && exitCode == 0) { log.Warning("Agent connection was forcibly closed. Exit code was 0, so agent shutdown OK"); } else { var stopError = $"Agent connection was forcibly closed. Exit code was {exitCode?.ToString() ?? "unknown"}. {Environment.NewLine}{ExceptionHelper.BuildMessageAndStackTrace(se)}"; log.Error(stopError); // Stop error with no unload error, just rethrow if (unloadException == null) { throw; } // Both kinds of errors, throw exception with combined message throw new NUnitEngineUnloadException(ExceptionHelper.BuildMessage(unloadException) + Environment.NewLine + stopError); } } catch (Exception e) { var stopError = "Failed to stop the remote agent." + Environment.NewLine + ExceptionHelper.BuildMessageAndStackTrace(e); log.Error(stopError); // Stop error with no unload error, just rethrow if (unloadException == null) { throw; } // Both kinds of errors, throw exception with combined message throw new NUnitEngineUnloadException(ExceptionHelper.BuildMessage(unloadException) + Environment.NewLine + stopError); } finally { _agent = 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); } } }
public void Stop() { _remoteAgent.Stop(); }