/// <summary> /// Load a TestPackage for possible execution /// </summary> /// <returns>A TestEngineResult.</returns> protected override TestEngineResult LoadPackage() { log.Info("Loading " + TestPackage.Name); Unload(); try { if (_agent == null) { _agent = _agency.GetAgent(TestPackage, 30000); if (_agent == null) throw new Exception("Unable to acquire remote process agent"); } if (_remoteRunner == null) _remoteRunner = _agent.CreateRunner(TestPackage); return _remoteRunner.Load(); } catch(Exception) { // TODO: Check if this is really needed // Clean up if the load failed Unload(); throw; } }
//public override void Stop() //{ // foreach( KeyValuePair<Guid,AgentRecord> pair in agentData ) // { // AgentRecord r = pair.Value; // if ( !r.Process.HasExited ) // { // if ( r.Agent != null ) // { // r.Agent.Stop(); // r.Process.WaitForExit(10000); // } // if ( !r.Process.HasExited ) // r.Process.Kill(); // } // } // agentData.Clear(); // base.Stop (); //} #endregion #region Public Methods - Called by Agents public void Register( ITestAgent agent ) { AgentRecord r = _agentData[agent.Id]; if ( r == null ) throw new ArgumentException( string.Format("Agent {0} is not in the agency database", agent.Id), "agentId"); r.Agent = agent; }
public AgentRecord this[ITestAgent agent] { get { foreach( KeyValuePair<Guid, AgentRecord> entry in agentData) { AgentRecord r = entry.Value; if ( r.Agent == agent ) return r; } return null; } }
public AgentRecord( Guid id, Process p, ITestAgent a, AgentStatus s ) { this.Id = id; this.Process = p; this.Agent = a; this.Status = s; }
public void ReleaseAgent( ITestAgent agent ) { AgentRecord r = _agentData[agent.Id]; if (r == null) log.Error(string.Format("Unable to release agent {0} - not in database", agent.Id)); else { r.Status = AgentStatus.Ready; log.Debug("Releasing agent " + agent.Id.ToString()); } }
protected override void Dispose(bool disposing) { base.Dispose(disposing); try { if (disposing && _agent != null) { log.Info("Stopping remote agent"); _agent.Stop(); _agent = null; } } catch (Exception e) { log.Error("Failed to stop the remote agent. {0}", e.Message); _agent = null; } }
/// <summary> /// Load a TestPackage for possible execution /// </summary> /// <returns>A TestEngineResult.</returns> protected override TestEngineResult LoadPackage() { log.Info("Loading " + TestPackage.Name); Unload(); try { if (_agent == null) { // Increase the timeout to give time to attach a debugger bool debug = TestPackage.GetSetting(PackageSettings.DebugAgent, false) || TestPackage.GetSetting(PackageSettings.PauseBeforeRun, false); _agent = _agency.GetAgent(TestPackage, debug ? DEBUG_TIMEOUT : NORMAL_TIMEOUT); if (_agent == null) throw new Exception("Unable to acquire remote process agent"); } if (_remoteRunner == null) _remoteRunner = _agent.CreateRunner(TestPackage); return _remoteRunner.Load(); } catch(Exception) { // TODO: Check if this is really needed // Clean up if the load failed Unload(); 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.BuildStackTrace(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"}. {ExceptionHelper.BuildMessage(se)}{Environment.NewLine}{ExceptionHelper.BuildStackTrace(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. {ExceptionHelper.BuildMessage(e)}{Environment.NewLine}{ExceptionHelper.BuildStackTrace(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); } } }
protected override void Dispose(bool disposing) { base.Dispose(disposing); if (disposing && _agent != null) { log.Info("Stopping remote agent"); _agent.Stop(); _agent = null; } }
//public override void Stop() //{ // foreach( KeyValuePair<Guid,AgentRecord> pair in agentData ) // { // AgentRecord r = pair.Value; // if ( !r.Process.HasExited ) // { // if ( r.Agent != null ) // { // r.Agent.Stop(); // r.Process.WaitForExit(10000); // } // if ( !r.Process.HasExited ) // r.Process.Kill(); // } // } // agentData.Clear(); // base.Stop (); //} public void Register(Guid agentId, ITestAgent agent) { _agentStore.Register(agentId, agent); }
public void Register(ITestAgent agent) { _agentStore.Register(agent); }
private void CreateAgentAndRunner(bool enableDebug, string agentArgs) { if (_agent == null) { _agent = Services.TestAgency.GetAgent( RuntimeFramework, 30000, enableDebug, agentArgs); if (_agent == null) throw new Exception("Unable to acquire remote process agent"); } if (_remoteRunner == null) _remoteRunner = _agent.CreateRunner(TestPackage); }
public override void Dispose() { if (_agent != null) { log.Info("Stopping remote agent"); _agent.Stop(); _agent = null; } }
public RemoteTestAgentProxy(ITestAgent remoteAgent, Guid id) { _remoteAgent = remoteAgent; Id = id; }
public AgentLease(TestAgency agency, Guid id, ITestAgent remoteAgent) { _agency = agency; Id = id; _remoteAgent = remoteAgent; }
public void Register(ITestAgent agent) { _agency.Register(agent); }