Esempio n. 1
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);
        }
Esempio n. 2
0
        public static void AgentIsNotReadyWhenStarted()
        {
            var database = new AgentStore();

            database.Start(DummyAgent.Id, DummyProcess);
            Assert.That(database.IsReady(DummyAgent.Id, out _), Is.False);
        }
Esempio n. 3
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);
        }
Esempio n. 4
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));
        }