コード例 #1
0
        public static void IdCannotBeReused()
        {
            var database = new AgentStore();

            database.Start(DummyAgent.Id, DummyProcess);
            Assert.That(() => database.Start(DummyAgent.Id, DummyProcess), Throws.ArgumentException.With.Property("ParamName").EqualTo("agentId"));

            database.Register(DummyAgent);
            Assert.That(() => database.Start(DummyAgent.Id, DummyProcess), Throws.ArgumentException.With.Property("ParamName").EqualTo("agentId"));

            database.MarkTerminated(DummyAgent.Id);
            Assert.That(() => database.Start(DummyAgent.Id, DummyProcess), Throws.ArgumentException.With.Property("ParamName").EqualTo("agentId"));
        }
コード例 #2
0
        public static void AgentIsNotReadyWhenStarted()
        {
            var database = new AgentStore();

            database.Start(DummyAgent.Id, DummyProcess);
            Assert.That(database.IsReady(DummyAgent.Id, out _), Is.False);
        }
コード例 #3
0
        public static void ConcurrentOperationsDoNotCorruptState()
        {
            var database = new AgentStore();

            RunActionConcurrently(() =>
            {
                for (var i = 0; i < 1000; i++)
                {
                    var id = Guid.NewGuid();

                    Assert.That(database.IsAgentProcessActive(id, out _), Is.False);
                    Assert.That(database.IsReady(id, out _), Is.False);

                    database.Start(id, DummyProcess);
                    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.MarkTerminated(id);
                    Assert.That(database.IsAgentProcessActive(id, out _), Is.False);
                    Assert.That(database.IsReady(id, out _), Is.False);
                }
            }, threadCount: Environment.ProcessorCount);
        }
コード例 #4
0
        public static void AgentMustNotRegisterAfterTerminating()
        {
            var database = new AgentStore();

            database.Start(DummyAgent.Id, DummyProcess);
            database.MarkTerminated(DummyAgent.Id);
            Assert.That(() => database.Register(DummyAgent), Throws.ArgumentException.With.Property("ParamName").EqualTo("agent"));
        }
コード例 #5
0
        public static void AgentIsRunningWhenStarted()
        {
            var database = new AgentStore();

            database.Start(DummyAgent.Id, DummyProcess);
            Assert.That(database.IsAgentProcessActive(DummyAgent.Id, out var process), Is.True);
            Assert.That(process, Is.SameAs(DummyProcess));
        }
コード例 #6
0
        public static void AgentIsNotReadyWhenTerminated()
        {
            var database = new AgentStore();

            database.Start(DummyAgent.Id, DummyProcess);
            database.Register(DummyAgent);
            database.MarkTerminated(DummyAgent.Id);
            Assert.That(database.IsReady(DummyAgent.Id, out _), Is.False);
        }
コード例 #7
0
        public static void AgentIsReadyWhenRegistered()
        {
            var database = new AgentStore();

            database.Start(DummyAgent.Id, DummyProcess);
            database.Register(DummyAgent);
            Assert.That(database.IsReady(DummyAgent.Id, out var registeredAgent), Is.True);
            Assert.That(registeredAgent, Is.SameAs(DummyAgent));
        }
コード例 #8
0
        private Process LaunchAgentProcess(TestPackage package, Guid agentId)
        {
            string runtimeSetting = package.GetSetting(EnginePackageSettings.RuntimeFramework, "");

            // TEMPORARY Guard in preparation for removing Runtime.Any
            Guard.OperationValid(runtimeSetting.Length > 0, "LaunchAgentProcess called with no runtime specified");

            var targetRuntime = RuntimeFramework.Parse(runtimeSetting);

            bool   useX86Agent     = package.GetSetting(EnginePackageSettings.RunAsX86, false);
            bool   debugTests      = package.GetSetting(EnginePackageSettings.DebugTests, false);
            bool   debugAgent      = package.GetSetting(EnginePackageSettings.DebugAgent, false);
            string traceLevel      = package.GetSetting(EnginePackageSettings.InternalTraceLevel, "Off");
            bool   loadUserProfile = package.GetSetting(EnginePackageSettings.LoadUserProfile, false);
            string workDirectory   = package.GetSetting(EnginePackageSettings.WorkDirectory, string.Empty);

            var agentArgs = new StringBuilder();

            // Set options that need to be in effect before the package
            // is loaded by using the command line.
            agentArgs.Append("--pid=").Append(Process.GetCurrentProcess().Id);
            if (traceLevel != "Off")
            {
                agentArgs.Append(" --trace:").EscapeProcessArgument(traceLevel);
            }
            if (debugAgent)
            {
                agentArgs.Append(" --debug-agent");
            }
            if (workDirectory != string.Empty)
            {
                agentArgs.Append(" --work=").EscapeProcessArgument(workDirectory);
            }

            log.Info("Getting {0} agent for use under {1}", useX86Agent ? "x86" : "standard", targetRuntime);

            if (!_runtimeService.IsAvailable(targetRuntime.Id))
            {
                throw new ArgumentException(
                          string.Format("The {0} framework is not available", targetRuntime),
                          "framework");
            }

            string agentExePath = GetTestAgentExePath(useX86Agent);

            if (!File.Exists(agentExePath))
            {
                throw new FileNotFoundException(
                          $"{Path.GetFileName(agentExePath)} could not be found.", agentExePath);
            }

            log.Debug("Using testcentric-agent at " + agentExePath);

            Process p = new Process();

            p.StartInfo.UseShellExecute = false;
            p.StartInfo.CreateNoWindow  = true;
            p.EnableRaisingEvents       = true;
            p.Exited += (sender, e) => OnAgentExit((Process)sender, agentId);
            string arglist = agentId.ToString() + " " + ServerUrl + " " + agentArgs;

            targetRuntime = ServiceContext.GetService <RuntimeFrameworkService>().GetBestAvailableFramework(targetRuntime);

            if (targetRuntime.Runtime == Runtime.Mono)
            {
                p.StartInfo.FileName = targetRuntime.MonoExePath;
                string monoOptions = "--runtime=v" + targetRuntime.ClrVersion.ToString(3);
                if (debugTests || debugAgent)
                {
                    monoOptions += " --debug";
                }
                p.StartInfo.Arguments = string.Format("{0} \"{1}\" {2}", monoOptions, agentExePath, arglist);
            }
            else if (targetRuntime.Runtime == Runtime.Net)
            {
                p.StartInfo.FileName = agentExePath;
                // Override the COMPLUS_Version env variable, this would cause CLR meta host to run a CLR of the specific version
                string envVar = "v" + targetRuntime.ClrVersion.ToString(3);
                p.StartInfo.EnvironmentVariables["COMPLUS_Version"] = envVar;
                // Leave a marker that we have changed this variable, so that the agent could restore it for any code or child processes running within the agent
                string cpvOriginal = Environment.GetEnvironmentVariable("COMPLUS_Version");
                p.StartInfo.EnvironmentVariables["TestAgency_COMPLUS_Version_Original"] = string.IsNullOrEmpty(cpvOriginal) ? "NULL" : cpvOriginal;
                p.StartInfo.Arguments       = arglist;
                p.StartInfo.LoadUserProfile = loadUserProfile;
            }
            else
            {
                p.StartInfo.FileName  = agentExePath;
                p.StartInfo.Arguments = arglist;
            }

            p.Start();
            log.Debug("Launched Agent process {0} - see testcentric-agent_{0}.log", p.Id);
            log.Debug("Command line: \"{0}\" {1}", p.StartInfo.FileName, p.StartInfo.Arguments);

            _agents.Start(agentId, p);
            return(p);
        }