Ejemplo n.º 1
0
        public bool Start()
        {
            log.Info("Agent starting");

            // Open the TCP channel so we can activate an ITestAgency instance from _agencyUrl
            _channel = TcpChannelUtils.GetTcpChannel(_currentMessageCounter);

            log.Info("Connecting to TestAgency at {0}", _agencyUrl);
            try
            {
                // Direct cast, not safe cast. If the cast fails we need a clear InvalidCastException message, not a null _agency.
                _agency = (ITestAgency)Activator.GetObject(typeof(ITestAgency), _agencyUrl);
            }
            catch (Exception ex)
            {
                log.Error("Unable to connect: {0}", ExceptionHelper.BuildMessageAndStackTrace(ex));
            }

            try
            {
                _agency.Register(_agentId, this);
                log.Debug("Registered with TestAgency");
            }
            catch (Exception ex)
            {
                log.Error("RemoteTestAgent: Failed to register with TestAgency. {0}", ExceptionHelper.BuildMessageAndStackTrace(ex));
                return(false);
            }

            return(true);
        }
Ejemplo n.º 2
0
        public TestAgencyTcpTransport(ITestAgency agency, int port = 0)
        {
            Guard.ArgumentNotNull(agency, nameof(agency));
            Guard.ArgumentValid(port >= IPEndPoint.MinPort && port <= IPEndPoint.MaxPort,
                                $"Port number {port} is invalid. Must be a positive integer less than or equal to {IPEndPoint.MaxPort}", nameof(port));

            _agency = agency;
            _server = new TcpServer(port);
        }
        public TestAgencyRemotingTransport(ITestAgency agency, string uri, int port)
        {
            Guard.ArgumentNotNull(agency, nameof(agency));
            Guard.ArgumentNotNullOrEmpty(uri, nameof(uri));

            _agency = agency;
            _uri    = uri;
            _port   = port;
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Construct a RemoteTestAgent
 /// </summary>
 public RemoteTestAgent( Guid agentId, ITestAgency agency, ServiceContext services )
     : base(agentId, agency, services) 
 {
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Consructs a TestAgent
 /// </summary>
 /// <param name="agentId"></param>
 /// <param name="agency"></param>
 public TestAgent(Guid agentId, ITestAgency agency, ServiceContext services)
 {
     this.agency   = agency;
     this.agentId  = agentId;
     this.services = services;
 }
Ejemplo n.º 6
0
        public static int Main(string[] args)
        {
            AgentId   = new Guid(args[0]);
            AgencyUrl = args[1];

            InternalTraceLevel traceLevel = InternalTraceLevel.Off;

            for (int i = 2; i < args.Length; i++)
            {
                string arg = args[i];

                // NOTE: we can test these strings exactly since
                // they originate from the engine itself.
                if (arg == "--debug-agent")
                {
                    if (!Debugger.IsAttached)
                    {
                        Debugger.Launch();
                    }
                }
                else if (arg.StartsWith("--trace:"))
                {
                    traceLevel = (InternalTraceLevel)Enum.Parse(typeof(InternalTraceLevel), arg.Substring(8));
                }
            }

            // Initialize trace so we can see what's happening
            int    pid     = Process.GetCurrentProcess().Id;
            string logname = string.Format(LOG_FILE_FORMAT, pid);

            InternalTrace.Initialize(logname, traceLevel);

            log.Info("Agent process {0} starting", pid);
            log.Info("Running under version {0}, {1}",
                     Environment.Version,
                     RuntimeFramework.CurrentFramework.DisplayName);

            // Restore the COMPLUS_Version env variable if it's been overridden by TestAgency::LaunchAgentProcess
            try
            {
                string cpvOriginal = Environment.GetEnvironmentVariable("TestAgency_COMPLUS_Version_Original");
                if (!string.IsNullOrEmpty(cpvOriginal))
                {
                    log.Debug("Agent process has the COMPLUS_Version environment variable value \"{0}\" overridden with \"{1}\", restoring the original value.", cpvOriginal, Environment.GetEnvironmentVariable("COMPLUS_Version"));
                    Environment.SetEnvironmentVariable("TestAgency_COMPLUS_Version_Original", null, EnvironmentVariableTarget.Process);                     // Erase marker
                    Environment.SetEnvironmentVariable("COMPLUS_Version", (cpvOriginal == "NULL" ? null : cpvOriginal), EnvironmentVariableTarget.Process); // Restore original (which might be n/a)
                }
            }
            catch (Exception ex)
            {
                log.Warning("Failed to restore the COMPLUS_Version variable. " + ex.Message); // Proceed with running tests anyway
            }

            // Create TestEngine - this program is
            // conceptually part of  the engine and
            // can access it's internals as needed.
            TestEngine engine = new TestEngine();

            // TODO: We need to get this from somewhere. Argument?
            engine.InternalTraceLevel = InternalTraceLevel.Debug;

            // Custom Service Initialization
            //log.Info("Adding Services");
            engine.Services.Add(new SettingsService(false));
            engine.Services.Add(new ExtensionService());
            engine.Services.Add(new ProjectService());
            engine.Services.Add(new DomainManager());
            engine.Services.Add(new InProcessTestRunnerFactory());
            engine.Services.Add(new DriverService());
            //engine.Services.Add( new TestLoader() );

            // Initialize Services
            log.Info("Initializing Services");
            engine.Initialize();

            Channel = ServerUtilities.GetTcpChannel();

            log.Info("Connecting to TestAgency at {0}", AgencyUrl);
            try
            {
                Agency = Activator.GetObject(typeof(ITestAgency), AgencyUrl) as ITestAgency;
            }
            catch (Exception ex)
            {
                log.Error("Unable to connect", ex);
            }

            if (Channel != null)
            {
                log.Info("Starting RemoteTestAgent");
                RemoteTestAgent agent = new RemoteTestAgent(AgentId, Agency, engine.Services);

                try
                {
                    if (agent.Start())
                    {
                        log.Debug("Waiting for stopSignal");
                        agent.WaitForStop();
                        log.Debug("Stop signal received");
                    }
                    else
                    {
                        log.Error("Failed to start RemoteTestAgent");
                    }
                }
                catch (Exception ex)
                {
                    log.Error("Exception in RemoteTestAgent", ex);
                }

                //log.Info("Unregistering Channel");
                try
                {
                    ChannelServices.UnregisterChannel(Channel);
                }
                catch (Exception ex)
                {
                    log.Error("ChannelServices.UnregisterChannel threw an exception", ex);
                }
            }

            log.Info("Agent process {0} exiting", Process.GetCurrentProcess().Id);

            return(0);
        }
Ejemplo n.º 7
0
        public static int Main(string[] args)
        {
            AgentId = new Guid(args[0]);
            AgencyUrl = args[1];

            bool pause = false, verbose = false;
            for (int i = 2; i < args.Length; i++)
                switch (args[i])
                {
                    case "--pause":
                        pause = true;
                        break;
                    case "--verbose":
                        verbose = true;
                        break;
                }
#if DEBUG
            if (pause)
                System.Windows.Forms.MessageBox.Show("Attach debugger if desired, then press OK", "NUnit-Agent");
#endif

            // Create SettingsService early so we know the trace level right at the start
            SettingsService settingsService = new SettingsService("NUnit30Settings.xml", false);
            //InternalTrace.Initialize("nunit-agent_%p.log", (InternalTraceLevel)settingsService.GetSetting("Options.InternalTraceLevel", InternalTraceLevel.Default));

            //log.Info("Agent process {0} starting", Process.GetCurrentProcess().Id);
            //log.Info("Running under version {0}, {1}", 
            //    Environment.Version, 
            //    RuntimeFramework.CurrentFramework.DisplayName);

            if (verbose)
            {
                Console.WriteLine("Agent process {0} starting", Process.GetCurrentProcess().Id);
                Console.WriteLine("Running under version {0}, {1}",
                    Environment.Version,
                    RuntimeFramework.CurrentFramework.DisplayName);
            }

            // Create TestEngine - this program is
            // conceptually part of  the engine and
            // can access it's internals as needed.
            TestEngine engine = new TestEngine();
            
            // Custom Service Initialization
            //log.Info("Adding Services");
            engine.Services.Add(settingsService);
            engine.Services.Add(new ProjectService());
            engine.Services.Add(new DomainManager());
            engine.Services.Add(new InProcessTestRunnerFactory());
            engine.Services.Add(new DriverFactory());
            //engine.Services.Add( new TestLoader() );

            // Initialize Services
            //log.Info("Initializing Services");
            engine.Services.ServiceManager.InitializeServices();

            Channel = ServerUtilities.GetTcpChannel();

            //log.Info("Connecting to TestAgency at {0}", AgencyUrl);
            try
            {
                Agency = Activator.GetObject(typeof(ITestAgency), AgencyUrl) as ITestAgency;
            }
            catch (Exception ex)
            {
                Console.WriteLine("Unable to connect\r\n{0}", ex);
                //log.Error("Unable to connect", ex);
            }

            if (Channel != null)
            {
                //log.Info("Starting RemoteTestAgent");
                RemoteTestAgent agent = new RemoteTestAgent(AgentId, Agency, engine.Services);

                try
                {
                    if (agent.Start())
                    {
                        //log.Debug("Waiting for stopSignal");
                        agent.WaitForStop();
                        //log.Debug("Stop signal received");
                    }
                    else
                        Console.WriteLine("Failed to start RemoteTestAgent");
                        //log.Error("Failed to start RemoteTestAgent");
                }
                catch (Exception ex)
                {
                    //log.Error("Exception in RemoteTestAgent", ex);
                    Console.WriteLine("Exception in RemoteTestAgent", ex);
                }

                //log.Info("Unregistering Channel");
                try
                {
                    ChannelServices.UnregisterChannel(Channel);
                }
                catch (Exception ex)
                {
                    //log.Error("ChannelServices.UnregisterChannel threw an exception", ex);
                    Console.WriteLine("ChannelServices.UnregisterChannel threw an exception\r\n{0}", ex);
                }
            }

            if (verbose)
                Console.WriteLine("Agent process {0} exiting", Process.GetCurrentProcess().Id);
            //log.Info("Agent process {0} exiting", Process.GetCurrentProcess().Id);
            //InternalTrace.Close();

            return 0;
        }
Ejemplo n.º 8
0
        public static int Main(string[] args)
        {
            AgentId   = new Guid(args[0]);
            AgencyUrl = args[1];

#if DEBUG
            bool pause = false;
#endif
            bool verbose = false;
            for (int i = 2; i < args.Length; i++)
            {
                switch (args[i])
                {
#if DEBUG
                case "--pause":
                    pause = true;
                    break;
#endif
                case "--verbose":
                    verbose = true;
                    break;
                }
            }
#if DEBUG
            if (pause)
            {
                System.Windows.Forms.MessageBox.Show("Attach debugger if desired, then press OK", "NUnit-Agent");
            }
#endif

            // Create SettingsService early so we know the trace level right at the start
            SettingsService settingsService = new SettingsService(false);
            //InternalTrace.Initialize("nunit-agent_%p.log", (InternalTraceLevel)settingsService.GetSetting("Options.InternalTraceLevel", InternalTraceLevel.Default));

            //log.Info("Agent process {0} starting", Process.GetCurrentProcess().Id);
            //log.Info("Running under version {0}, {1}",
            //    Environment.Version,
            //    RuntimeFramework.CurrentFramework.DisplayName);

            if (verbose)
            {
                Console.WriteLine("Agent process {0} starting", Process.GetCurrentProcess().Id);
                Console.WriteLine("Running under version {0}, {1}",
                                  Environment.Version,
                                  RuntimeFramework.CurrentFramework.DisplayName);
            }

            // Create TestEngine - this program is
            // conceptually part of  the engine and
            // can access it's internals as needed.
            TestEngine engine = new TestEngine();

            // Custom Service Initialization
            //log.Info("Adding Services");
            engine.Services.Add(settingsService);
            engine.Services.Add(new ExtensionService());
            engine.Services.Add(new ProjectService());
            engine.Services.Add(new DomainManager());
            engine.Services.Add(new InProcessTestRunnerFactory());
            engine.Services.Add(new DriverService());
            //engine.Services.Add( new TestLoader() );

            // Initialize Services
            //log.Info("Initializing Services");
            engine.Initialize();

            Channel = ServerUtilities.GetTcpChannel();

            //log.Info("Connecting to TestAgency at {0}", AgencyUrl);
            try
            {
                Agency = Activator.GetObject(typeof(ITestAgency), AgencyUrl) as ITestAgency;
            }
            catch (Exception ex)
            {
                Console.WriteLine("Unable to connect\r\n{0}", ex);
                //log.Error("Unable to connect", ex);
            }

            if (Channel != null)
            {
                //log.Info("Starting RemoteTestAgent");
                RemoteTestAgent agent = new RemoteTestAgent(AgentId, Agency, engine.Services);

                try
                {
                    if (agent.Start())
                    {
                        //log.Debug("Waiting for stopSignal");
                        agent.WaitForStop();
                        //log.Debug("Stop signal received");
                    }
                    else
                    {
                        Console.WriteLine("Failed to start RemoteTestAgent");
                    }
                    //log.Error("Failed to start RemoteTestAgent");
                }
                catch (Exception ex)
                {
                    //log.Error("Exception in RemoteTestAgent", ex);
                    Console.WriteLine("Exception in RemoteTestAgent\r\n{0}", ex);
                }

                //log.Info("Unregistering Channel");
                try
                {
                    ChannelServices.UnregisterChannel(Channel);
                }
                catch (Exception ex)
                {
                    //log.Error("ChannelServices.UnregisterChannel threw an exception", ex);
                    Console.WriteLine("ChannelServices.UnregisterChannel threw an exception\r\n{0}", ex);
                }
            }

            if (verbose)
            {
                Console.WriteLine("Agent process {0} exiting", Process.GetCurrentProcess().Id);
            }
            //log.Info("Agent process {0} exiting", Process.GetCurrentProcess().Id);
            //InternalTrace.Close();

            return(0);
        }
Ejemplo n.º 9
0
 /// <summary>
 /// Construct a RemoteTestAgent
 /// </summary>
 public RemoteTestAgent(Guid agentId, ITestAgency agency, ServiceContext services)
     : base(agentId, agency, services)
 {
 }
Ejemplo n.º 10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TestAgent"/> class.
 /// </summary>
 /// <param name="agentId">The identifier of the agent.</param>
 /// <param name="agency">The agency that this agent is associated with.</param>
 /// <param name="services">The services available to the agent.</param>
 public TestAgent( Guid agentId, ITestAgency agency, IServiceLocator services )
 {
     this.agency = agency;
     this.agentId = agentId;
     this.services = services;
 }
Ejemplo n.º 11
0
        public static int Main(string[] args)
        {
            AgentId = new Guid(args[0]);
            AgencyUrl = args[1];

            InternalTraceLevel traceLevel = InternalTraceLevel.Off;

            for (int i = 2; i < args.Length; i++)
            {
                string arg = args[i];
                
                // NOTE: we can test these strings exactly since
                // they originate from the engine itself.
                if (arg == "--debug-agent")
                {
                    if (!Debugger.IsAttached)
                        Debugger.Launch();
                }
                else if (arg.StartsWith("--trace:"))
                {
                    traceLevel = (InternalTraceLevel)Enum.Parse(typeof(InternalTraceLevel), arg.Substring(8));
                }
            }

            // Initialize trace so we can see what's happening
            int pid = Process.GetCurrentProcess().Id;
            string logname = string.Format(LOG_FILE_FORMAT, pid);
            InternalTrace.Initialize(logname, traceLevel);

            log.Info("Agent process {0} starting", pid);
            log.Info("Running under version {0}, {1}",
                Environment.Version,
                RuntimeFramework.CurrentFramework.DisplayName);

            // Create TestEngine - this program is
            // conceptually part of  the engine and
            // can access it's internals as needed.
            TestEngine engine = new TestEngine();

            // TODO: We need to get this from somewhere. Argument?
            engine.InternalTraceLevel = InternalTraceLevel.Debug;
            
            // Custom Service Initialization
            //log.Info("Adding Services");
            engine.Services.Add(new SettingsService(false));
            engine.Services.Add(new ExtensionService());
            engine.Services.Add(new ProjectService());
            engine.Services.Add(new DomainManager());
            engine.Services.Add(new InProcessTestRunnerFactory());
            engine.Services.Add(new DriverService());
            //engine.Services.Add( new TestLoader() );

            // Initialize Services
            log.Info("Initializing Services");
            engine.Initialize();

            Channel = ServerUtilities.GetTcpChannel();

            log.Info("Connecting to TestAgency at {0}", AgencyUrl);
            try
            {
                Agency = Activator.GetObject(typeof(ITestAgency), AgencyUrl) as ITestAgency;
            }
            catch (Exception ex)
            {
                log.Error("Unable to connect", ex);
            }

            if (Channel != null)
            {
                log.Info("Starting RemoteTestAgent");
                RemoteTestAgent agent = new RemoteTestAgent(AgentId, Agency, engine.Services);

                try
                {
                    if (agent.Start())
                    {
                        log.Debug("Waiting for stopSignal");
                        agent.WaitForStop();
                        log.Debug("Stop signal received");
                    }
                    else
                        log.Error("Failed to start RemoteTestAgent");
                }
                catch (Exception ex)
                {
                    log.Error("Exception in RemoteTestAgent", ex);
                }

                //log.Info("Unregistering Channel");
                try
                {
                    ChannelServices.UnregisterChannel(Channel);
                }
                catch (Exception ex)
                {
                    log.Error("ChannelServices.UnregisterChannel threw an exception", ex);
                }
            }

            log.Info("Agent process {0} exiting", Process.GetCurrentProcess().Id);

            return 0;
        }
Ejemplo n.º 12
0
 /// <summary>
 /// Construct a RemoteTestAgent
 /// </summary>
 public RemoteTestAgent(Guid agentId, ITestAgency agency, IServiceLocator services)
     : base(agentId, agency, services)
 {
 }
Ejemplo n.º 13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TestAgent"/> class.
 /// </summary>
 /// <param name="agentId">The identifier of the agent.</param>
 /// <param name="agency">The agency that this agent is associated with.</param>
 /// <param name="services">The services available to the agent.</param>
 public TestAgent(Guid agentId, ITestAgency agency, IServiceLocator services)
 {
     this.agency   = agency;
     this.agentId  = agentId;
     this.services = services;
 }
Ejemplo n.º 14
0
 /// <summary>
 /// Consructs a TestAgent
 /// </summary>
 /// <param name="agentId"></param>
 /// <param name="agency"></param>
 public TestAgent( Guid agentId, ITestAgency agency, ServiceContext services )
 {
     this.agency = agency;
     this.agentId = agentId;
     this.services = services;
 }
Ejemplo n.º 15
0
 /// <summary>
 /// Construct a RemoteTestAgent
 /// </summary>
 public RemoteTestAgent( Guid agentId, ITestAgency agency, IServiceLocator services )
     : base(agentId, agency, services) 
 {
 }