From 6fa3dffad25a22a098f549b8c71790c358b963d9 Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Thu, 1 Mar 2012 03:23:10 +0000 Subject: [PATCH] Use a fully stubbed out MockConsole for unit tests rather than inheriting from CommandConsole. This is so that the static MainConsole.Instance doesn't retain references to methods registered by scene and other modules to service commands. This prevents the scene from being garbage collected at the end of a test. This is not the final thing preventing GC - next up is the timer started by SimStatsReporter that holds a reference to Scene that prevents end of test gc. --- OpenSim/Framework/Console/MockConsole.cs | 59 ++++++++++++-------- OpenSim/Tests/Common/Helpers/SceneHelpers.cs | 2 +- 2 files changed, 38 insertions(+), 23 deletions(-) diff --git a/OpenSim/Framework/Console/MockConsole.cs b/OpenSim/Framework/Console/MockConsole.cs index a29b370857..4d8751f5f6 100644 --- a/OpenSim/Framework/Console/MockConsole.cs +++ b/OpenSim/Framework/Console/MockConsole.cs @@ -29,6 +29,7 @@ using System; using System.Threading; using System.Collections.Generic; using System.Text; +using System.Xml; namespace OpenSim.Framework.Console { @@ -37,28 +38,42 @@ namespace OpenSim.Framework.Console /// Don't use this except for Unit Testing or you're in for a world of hurt when the /// sim gets to ReadLine /// - public class MockConsole : CommandConsole + public class MockConsole : ICommandConsole { - public MockConsole(string defaultPrompt) : base(defaultPrompt) - { - } - public override void Output(string text) - { - } - public override void Output(string text, string level) - { - } + private MockCommands m_commands = new MockCommands(); - public override string ReadLine(string p, bool isCommand, bool e) - { - //Thread.CurrentThread.Join(1000); - return string.Empty; - } - public override void UnlockOutput() - { - } - public override void LockOutput() - { - } + public ICommands Commands { get { return m_commands; } } + + public void Prompt() {} + + public void RunCommand(string cmd) {} + + public string ReadLine(string p, bool isCommand, bool e) { return ""; } + + public object ConsoleScene { get { return null; } } + + public void Output(string text, string level) {} + public void Output(string text) {} + public void OutputFormat(string format, params object[] components) {} + + public string CmdPrompt(string p) { return ""; } + public string CmdPrompt(string p, string def) { return ""; } + public string CmdPrompt(string p, List excludedCharacters) { return ""; } + public string CmdPrompt(string p, string def, List excludedCharacters) { return ""; } + + public string CmdPrompt(string prompt, string defaultresponse, List options) { return ""; } + + public string PasswdPrompt(string p) { return ""; } } -} + + public class MockCommands : ICommands + { + public void FromXml(XmlElement root, CommandDelegate fn) {} + public List GetHelp(string[] cmd) { return null; } + public void AddCommand(string module, bool shared, string command, string help, string longhelp, CommandDelegate fn) {} + public void AddCommand(string module, bool shared, string command, string help, string longhelp, string descriptivehelp, CommandDelegate fn) {} + public string[] FindNextOption(string[] cmd, bool term) { return null; } + public string[] Resolve(string[] cmd) { return null; } + public XmlElement GetXml(XmlDocument doc) { return null; } + } +} \ No newline at end of file diff --git a/OpenSim/Tests/Common/Helpers/SceneHelpers.cs b/OpenSim/Tests/Common/Helpers/SceneHelpers.cs index e2d471bb8c..d9f8a148e9 100644 --- a/OpenSim/Tests/Common/Helpers/SceneHelpers.cs +++ b/OpenSim/Tests/Common/Helpers/SceneHelpers.cs @@ -113,7 +113,7 @@ namespace OpenSim.Tests.Common Console.WriteLine("Setting up test scene {0}", name); // We must set up a console otherwise setup of some modules may fail - MainConsole.Instance = new MockConsole("TEST PROMPT"); + MainConsole.Instance = new MockConsole(); RegionInfo regInfo = new RegionInfo(x, y, new IPEndPoint(IPAddress.Loopback, 9000), "127.0.0.1"); regInfo.RegionName = name;