Ejemplo n.º 1
0
        // Same test than Kill, but when the scheduler has not yet ticked
        public void KillNotTicked()
        {
            var mock           = new Program.MockAction();
            var killedByName   = Enumerable.Range(0, 2).Select(i => this.manager.Spawn(null, name: "KillMeByName", onDone: mock.Action)).ToList();
            var killedById     = this.manager.Spawn(null, onDone: mock.Action);
            var killedInTheEnd = Enumerable.Range(0, 2).Select(i => this.manager.Spawn(null, onDone: mock.Action)).ToList();

            this.manager.KillAll("KillMeByName");

            Assert.AreEqual(2, mock.CallCount);
            foreach (var p in killedByName)
            {
                Assert.IsFalse(p.Alive);
            }

            this.manager.Kill(killedById.ID);

            Assert.AreEqual(3, mock.CallCount);
            Assert.IsFalse(killedById.Alive);

            this.manager.KillAll();

            Assert.AreEqual(5, mock.CallCount);
            foreach (var p in killedInTheEnd)
            {
                Assert.IsFalse(p.Alive);
            }
            foreach (int i in Enumerable.Range(0, 5))
            {
                Assert.AreEqual(Program.ProcessResult.KILLED, mock.GetCallResult(i));
            }
        }
Ejemplo n.º 2
0
        public void KillAllSpawning()
        {
            // we check that processes can spawn new processes when being killed, and that we ignore those processes
            var mock = new Program.MockAction(p => this.manager.Spawn(null, "killme"));

            Program.Process process1 = this.manager.Spawn(null, "killme", mock.Action);
            Program.Process process2 = this.manager.Spawn(null, "killme", mock.Action);

            this.manager.KillAll("killme");

            Assert.IsFalse(process2.Alive);
            Assert.IsFalse(process1.Alive);
            Assert.AreEqual(2, mock.CallCount);

            var processes = new List <string>();

            this.manager.Log(s => processes.Add(s));

            Assert.AreEqual(2, processes.Count(s => s.Contains("killme")));

            // Although ignored at first because spawned during the KillAll call, a subsequent call to KillAll will kill them
            this.manager.KillAll("killme");
            processes.Clear();
            this.manager.Log(s => processes.Add(s));

            Assert.AreEqual(0, processes.Count(s => s.Contains("killme")));
        }
Ejemplo n.º 3
0
        public void UseOnce()
        {
            var mock     = new MockActionProcess();
            var mockDone = new Program.MockAction();
            var p        = this.manager.Spawn(mock.Action, period: 3, useOnce: true, onDone: mockDone.Action);

            this.tick();
            this.tick();

            Assert.IsFalse(mock.Called, "Not enough ticks, the action has not been called");
            Assert.IsFalse(mockDone.Called, "the onDone callback has not yes been called.");

            this.tick();

            Assert.AreEqual(1, mock.CallCount, "The action is called exactly on the tick number 'period'");
            Assert.IsFalse(p.Active, "The process is no longer active.");
            Assert.AreEqual(1, mockDone.CallCount, "the onDone callback has been called.");
        }