public static void ConcurrentOperationsDoNotCorruptState() { var database = new AgentStore(); RunActionConcurrently(() => { for (var i = 0; i < 1000; i++) { var id = Guid.NewGuid(); var process = new Process(); Assert.That(database.IsAgentProcessActive(id, out _), Is.False); Assert.That(database.IsReady(id, out _), Is.False); database.AddAgent(id, process); Assert.That(database.IsAgentProcessActive(id, out _), Is.True); Assert.That(database.IsReady(id, out _), Is.False); database.Register(new DummyTestAgent(id)); Assert.That(database.IsAgentProcessActive(id, out _), Is.True); Assert.That(database.IsReady(id, out _), Is.True); database.MarkProcessTerminated(process); Assert.That(database.IsAgentProcessActive(id, out _), Is.False); Assert.That(database.IsReady(id, out _), Is.False); } }, threadCount: Environment.ProcessorCount); }
public static void AgentIsNotReadyWhenStarted() { var database = new AgentStore(); database.AddAgent(DummyAgent.Id, DummyProcess); Assert.That(database.IsReady(DummyAgent.Id, out _), Is.False); }
public static void AgentIsNotReadyWhenTerminated() { var database = new AgentStore(); database.AddAgent(DummyAgent.Id, DummyProcess); database.Register(DummyAgent); database.MarkProcessTerminated(DummyProcess); Assert.That(database.IsReady(DummyAgent.Id, out _), Is.False); }
public static void AgentIsReadyWhenRegistered() { var database = new AgentStore(); database.AddAgent(DummyAgent.Id, DummyProcess); database.Register(DummyAgent); Assert.That(database.IsReady(DummyAgent.Id, out var registeredAgent), Is.True); Assert.That(registeredAgent, Is.SameAs(DummyAgent)); }
private ITestAgent CreateRemoteAgent(TestPackage package, RuntimeFramework targetRuntime) { var agentId = Guid.NewGuid(); var process = new AgentProcess(this, package, agentId); process.Exited += (sender, e) => OnAgentExit((Process)sender, agentId); process.Start(); log.Debug("Launched Agent process {0} - see testcentric-agent_{0}.log", process.Id); log.Debug("Command line: \"{0}\" {1}", process.StartInfo.FileName, process.StartInfo.Arguments); _agentStore.AddAgent(agentId, process); log.Debug($"Waiting for agent {agentId:B} to register"); const int pollTime = 200; // Increase the timeout to give time to attach a debugger bool debug = package.GetSetting(EnginePackageSettings.DebugAgent, false) || package.GetSetting(EnginePackageSettings.PauseBeforeRun, false); int waitTime = debug ? DEBUG_TIMEOUT : NORMAL_TIMEOUT; // Wait for agent registration based on the agent actually getting processor time to avoid falling over // under process starvation. while (waitTime > process.TotalProcessorTime.TotalMilliseconds && !process.HasExited) { Thread.Sleep(pollTime); if (_agentStore.IsReady(agentId, out var agent)) { log.Debug($"Returning new agent {agentId:B}"); switch (targetRuntime.Runtime.FrameworkIdentifier) { case FrameworkIdentifiers.NetFramework: return(new TestAgentRemotingProxy(agent, agentId)); case FrameworkIdentifiers.NetCoreApp: return(agent); default: throw new InvalidOperationException($"Invalid runtime: {targetRuntime.Runtime.FrameworkIdentifier}"); } } } return(null); }
private ITestAgent CreateRemoteAgent(TestPackage package, int waitTime) { var agentId = Guid.NewGuid(); var process = LaunchAgentProcess(package, agentId); log.Debug($"Waiting for agent {agentId:B} to register"); const int pollTime = 200; // Wait for agent registration based on the agent actually getting processor time to avoid falling over // under process starvation. while (waitTime > process.TotalProcessorTime.TotalMilliseconds && !process.HasExited) { Thread.Sleep(pollTime); if (_agents.IsReady(agentId, out var agent)) { log.Debug($"Returning new agent {agentId:B}"); return(new RemoteTestAgentProxy(agent, agentId)); } } return(null); }
public ITestAgent GetAgent(TestPackage package) { // Target Runtime must be specified by this point string runtimeSetting = package.GetSetting(EnginePackageSettings.TargetRuntimeFramework, ""); Guard.OperationValid(runtimeSetting.Length > 0, "LaunchAgentProcess called with no runtime specified"); // If target runtime is not available, something went wrong earlier var targetRuntime = RuntimeFramework.Parse(runtimeSetting); if (!_runtimeService.IsAvailable(targetRuntime.Id)) { throw new ArgumentException( string.Format("The {0} framework is not available", targetRuntime), "framework"); } var agentId = Guid.NewGuid(); string agencyUrl = targetRuntime.FrameworkName.Identifier == ".NETFramework" ? RemotingUrl : TcpEndPoint; var agentProcess = CreateAgentProcess(agentId, agencyUrl, package); agentProcess.Exited += (sender, e) => OnAgentExit((Process)sender); agentProcess.Start(); log.Debug("Launched Agent process {0} - see testcentric-agent_{0}.log", agentProcess.Id); log.Debug("Command line: \"{0}\" {1}", agentProcess.StartInfo.FileName, agentProcess.StartInfo.Arguments); _agentStore.AddAgent(agentId, agentProcess); log.Debug($"Waiting for agent {agentId:B} to register"); const int pollTime = 200; // Increase the timeout to give time to attach a debugger bool debug = package.GetSetting(EnginePackageSettings.DebugAgent, false) || package.GetSetting(EnginePackageSettings.PauseBeforeRun, false); int waitTime = debug ? DEBUG_TIMEOUT : NORMAL_TIMEOUT; // Wait for agent registration based on the agent actually getting processor time to avoid falling over // under process starvation. while (waitTime > agentProcess.TotalProcessorTime.TotalMilliseconds && !agentProcess.HasExited) { Thread.Sleep(pollTime); if (_agentStore.IsReady(agentId, out var agent)) { log.Debug($"Returning new agent {agentId:B}"); switch (targetRuntime.Runtime.FrameworkIdentifier) { case FrameworkIdentifiers.NetFramework: return(new TestAgentRemotingProxy(agent, agentId)); case FrameworkIdentifiers.NetCoreApp: return(agent); default: throw new InvalidOperationException($"Invalid runtime: {targetRuntime.Runtime.FrameworkIdentifier}"); } } } return(null); }