Exemplo n.º 1
0
        /// <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;
            }
        }
Exemplo n.º 2
0
        //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;
        }
Exemplo n.º 3
0
            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;
                }
            }
Exemplo n.º 4
0
 public AgentRecord( Guid id, Process p, ITestAgent a, AgentStatus s )
 {
     this.Id = id;
     this.Process = p;
     this.Agent = a;
     this.Status = s;
 }
Exemplo n.º 5
0
 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());
     }
 }
Exemplo n.º 6
0
        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;
            }
        }
Exemplo n.º 7
0
        /// <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;
            }
        }
Exemplo n.º 8
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.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);
                }
            }
        }
Exemplo n.º 9
0
        protected override void Dispose(bool disposing)
        {
            base.Dispose(disposing);

            if (disposing && _agent != null)
            {
                log.Info("Stopping remote agent");
                _agent.Stop();
                _agent = null;
            }
        }
Exemplo n.º 10
0
        //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);
        }
Exemplo n.º 11
0
 public void Register(ITestAgent agent)
 {
     _agentStore.Register(agent);
 }
Exemplo n.º 12
0
        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);
        }
Exemplo n.º 13
0
 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;
        }
Exemplo n.º 15
0
 public AgentLease(TestAgency agency, Guid id, ITestAgent remoteAgent)
 {
     _agency      = agency;
     Id           = id;
     _remoteAgent = remoteAgent;
 }
 public void Register(ITestAgent agent)
 {
     _agency.Register(agent);
 }