public static void Main(string[] args) { var options = new AgentOptions(args); var pid = Process.GetCurrentProcess().Id; var logName = $"testcentric-agent_{pid}.log"; InternalTrace.Initialize(Path.Combine(options.WorkDirectory, logName), options.TraceLevel); log = InternalTrace.GetLogger(typeof(TestCentricAgent)); if (options.DebugAgent || options.DebugTests) { TryLaunchDebugger(); } LocateAgencyProcess(options.AgencyPid); log.Info("Agent process {0} starting", pid); #if NET5_0 log.Info($"Running .NET 5.0 agent under {RuntimeInformation.FrameworkDescription}"); #elif NETCOREAPP3_1 log.Info($"Running .NET Core 3.1 agent under {RuntimeInformation.FrameworkDescription}"); #elif NETCOREAPP2_1 log.Info($"Running .NET Core 2.1 agent under {RuntimeInformation.FrameworkDescription}"); #elif NET40 log.Info("Running .NET Framework 4.0 agent"); #elif NET20 log.Info("Running .NET Framework 2.0 agent"); #endif log.Info("Starting RemoteTestAgent"); Agent = new RemoteTestAgent(options.AgentId); Agent.Transport = #if NETFRAMEWORK new TestCentric.Engine.Communication.Transports.Remoting.TestAgentRemotingTransport(Agent, options.AgencyUrl); #else new TestCentric.Engine.Communication.Transports.Tcp.TestAgentTcpTransport(Agent, options.AgencyUrl); #endif try { if (Agent.Start()) { WaitForStop(); } else { log.Error("Failed to start RemoteTestAgent"); Environment.Exit(AgentExitCodes.FAILED_TO_START_REMOTE_AGENT); } } catch (Exception ex) { log.Error("Exception in RemoteTestAgent. {0}", ExceptionHelper.BuildMessageAndStackTrace(ex)); Environment.Exit(AgentExitCodes.UNEXPECTED_EXCEPTION); } log.Info("Agent process {0} exiting cleanly", pid); Environment.Exit(AgentExitCodes.OK); }
public static void Main(string[] args) { var options = new AgentOptions(args); var pid = Process.GetCurrentProcess().Id; var logName = $"testcentric-agent_{pid}.log"; InternalTrace.Initialize(Path.Combine(options.WorkDirectory, logName), options.TraceLevel); log = InternalTrace.GetLogger(typeof(TestCentricAgent)); if (options.DebugAgent || options.DebugTests) { TryLaunchDebugger(); } LocateAgencyProcess(options.AgencyPid); log.Info($".NET 2.0 Agent process {pid} starting"); log.Info($" AgentId: {options.AgentId}"); log.Info($" AgencyUrl: {options.AgencyUrl}"); log.Info("Starting RemoteTestAgent"); Agent = new RemoteTestAgent(options.AgentId); Agent.Transport = new TestAgentRemotingTransport(Agent, options.AgencyUrl); try { if (Agent.Start()) { WaitForStop(); } else { log.Error("Failed to start RemoteTestAgent"); Environment.Exit(AgentExitCodes.FAILED_TO_START_REMOTE_AGENT); } } catch (Exception ex) { log.Error("Exception in RemoteTestAgent. {0}", ExceptionHelper.BuildMessageAndStackTrace(ex)); Environment.Exit(AgentExitCodes.UNEXPECTED_EXCEPTION); } log.Info("Agent process {0} exiting cleanly", pid); Environment.Exit(AgentExitCodes.OK); }
public static void Main(string[] args) { AgentId = new Guid(args[0]); AgencyUrl = args[1]; var traceLevel = InternalTraceLevel.Off; var pid = Process.GetCurrentProcess().Id; var debugArgPassed = false; var workDirectory = string.Empty; var agencyPid = string.Empty; 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") { debugArgPassed = true; } else if (arg.StartsWith("--trace:")) { traceLevel = (InternalTraceLevel)Enum.Parse(typeof(InternalTraceLevel), arg.Substring(8)); } else if (arg.StartsWith("--pid=")) { agencyPid = arg.Substring(6); } else if (arg.StartsWith("--work=")) { workDirectory = arg.Substring(7); } } var logName = $"nunit-agent_{pid}.log"; InternalTrace.Initialize(Path.Combine(workDirectory, logName), traceLevel); log = InternalTrace.GetLogger(typeof(NUnitTestAgent)); if (debugArgPassed) { TryLaunchDebugger(); } LocateAgencyProcess(agencyPid); log.Info("Agent process {0} starting", pid); log.Info("Running under version {0}, {1}", Environment.Version, RuntimeFramework.CurrentFramework.DisplayName); // Create CoreEngine var engine = new CoreEngine { WorkDirectory = workDirectory, InternalTraceLevel = traceLevel }; // Custom Service Initialization engine.Services.Add(new ExtensionService()); engine.Services.Add(new DomainManager()); engine.Services.Add(new InProcessTestRunnerFactory()); engine.Services.Add(new DriverService()); // Initialize Services log.Info("Initializing Services"); engine.InitializeServices(); log.Info("Starting RemoteTestAgent"); Agent = new RemoteTestAgent(AgentId, AgencyUrl, engine.Services); try { if (Agent.Start()) { WaitForStop(); } else { log.Error("Failed to start RemoteTestAgent"); Environment.Exit(AgentExitCodes.FAILED_TO_START_REMOTE_AGENT); } } catch (Exception ex) { log.Error("Exception in RemoteTestAgent. {0}", ExceptionHelper.BuildMessageAndStackTrace(ex)); Environment.Exit(AgentExitCodes.UNEXPECTED_EXCEPTION); } log.Info("Agent process {0} exiting cleanly", pid); Environment.Exit(AgentExitCodes.OK); }
public static void Main(string[] args) { AgentId = new Guid(args[0]); AgencyUrl = args[1]; InternalTraceLevel traceLevel = InternalTraceLevel.Off; int pid = Process.GetCurrentProcess().Id; bool debugArgPassed = false; string workDirectory = string.Empty; 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") { debugArgPassed = true; } else if (arg.StartsWith("--trace:")) { traceLevel = (InternalTraceLevel)Enum.Parse(typeof(InternalTraceLevel), arg.Substring(8)); } else if (arg.StartsWith("--pid=")) { int agencyProcessId = int.Parse(arg.Substring(6)); AgencyProcess = Process.GetProcessById(agencyProcessId); } else if (arg.StartsWith("--work=")) { workDirectory = arg.Substring(7); } } var logName = $"nunit-agent_{pid}.log"; InternalTrace.Initialize(Path.Combine(workDirectory, logName), traceLevel); log = InternalTrace.GetLogger(typeof(NUnitTestAgent)); if (debugArgPassed) { TryLaunchDebugger(); } 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()); // Initialize Services log.Info("Initializing Services"); engine.Initialize(); log.Info("Starting RemoteTestAgent"); Agent = new RemoteTestAgent(AgentId, AgencyUrl, engine.Services); try { if (Agent.Start()) { WaitForStop(); } else { log.Error("Failed to start RemoteTestAgent"); Environment.Exit(AgentExitCodes.FAILED_TO_START_REMOTE_AGENT); } } catch (Exception ex) { log.Error("Exception in RemoteTestAgent", ex); Environment.Exit(AgentExitCodes.UNEXPECTED_EXCEPTION); } log.Info("Agent process {0} exiting cleanly", pid); Environment.Exit(AgentExitCodes.OK); }
public void Setup() { logger = InternalTrace.GetLogger(typeof(LoggerTest)); }