From 57ab79e3312d9856a3534a1e2343b45c6cf74ac6 Mon Sep 17 00:00:00 2001 From: Sean Dague Date: Thu, 26 Feb 2009 21:29:16 +0000 Subject: * Update ScenePresenceTests to reflect current REST communication workflow. * Fixed an issue with AssetCache where it would break unit tests randomly. From: Arthur Rodrigo S Valadares --- OpenSim/Tests/Common/Mock/TestClient.cs | 58 ++++++------ OpenSim/Tests/Common/Setup/SceneSetupHelpers.cs | 113 ++++++++++++------------ 2 files changed, 91 insertions(+), 80 deletions(-) (limited to 'OpenSim/Tests') diff --git a/OpenSim/Tests/Common/Mock/TestClient.cs b/OpenSim/Tests/Common/Mock/TestClient.cs index 16c55ae..0635aab 100644 --- a/OpenSim/Tests/Common/Mock/TestClient.cs +++ b/OpenSim/Tests/Common/Mock/TestClient.cs @@ -29,6 +29,7 @@ using System; using System.Collections.Generic; using System.Net; using System.Reflection; +using System.Threading; using log4net; using OpenMetaverse; using OpenMetaverse.Packets; @@ -41,16 +42,17 @@ namespace OpenSim.Tests.Common.Mock public class TestClient : IClientAPI { private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - + // Mock testing variables public List sentdatapkt = new List(); public List sentpktpkt = new List(); - + EventWaitHandle wh = new EventWaitHandle (false, EventResetMode.AutoReset, "Crossing"); + // TODO: This is a really nasty (and temporary) means of telling the test client which scene to invoke setup // methods on when a teleport is requested - public Scene TeleportTargetScene; + public Scene TeleportTargetScene; private TestClient TeleportSceneClient; - + private IScene m_scene; // disable warning: public events, part of the public API @@ -272,7 +274,7 @@ namespace OpenSim.Tests.Common.Mock /// This agent's UUID /// private UUID m_agentId; - + /// /// The last caps seed url that this client was given. /// @@ -363,15 +365,15 @@ namespace OpenSim.Tests.Common.Mock { set { } } - + private uint m_circuitCode; public uint CircuitCode { get { return m_circuitCode; } set { m_circuitCode = value; } - } - + } + /// /// Constructor /// @@ -386,7 +388,7 @@ namespace OpenSim.Tests.Common.Mock m_scene = scene; CapsSeedUrl = agentData.CapsPath; } - + /// /// Attempt a teleport to the given region. /// @@ -395,9 +397,9 @@ namespace OpenSim.Tests.Common.Mock /// public void Teleport(ulong regionHandle, Vector3 position, Vector3 lookAt) { - OnTeleportLocationRequest(this, regionHandle, position, lookAt, 16); + OnTeleportLocationRequest(this, regionHandle, position, lookAt, 16); } - + public void CompleteMovement() { OnCompleteMovementToRegion(); @@ -501,46 +503,52 @@ namespace OpenSim.Tests.Common.Mock agentData.child = false; agentData.firstname = m_firstName; agentData.lastname = m_lastName; - + ICapabilitiesModule capsModule = m_scene.RequestModuleInterface(); agentData.CapsPath = capsModule.GetCapsPath(m_agentId); agentData.ChildrenCapSeeds = new Dictionary(capsModule.GetChildrenSeeds(m_agentId)); - + return agentData; } - + public virtual void InformClientOfNeighbour(ulong neighbourHandle, IPEndPoint neighbourExternalEndPoint) { m_log.DebugFormat("[TEST CLIENT]: Processing inform client of neighbour"); - + // In response to this message, we are going to make a teleport to the scene we've previous been told // about by test code (this needs to be improved). - AgentCircuitData newAgent = RequestClientInfo(); - + AgentCircuitData newAgent = RequestClientInfo(); + // Stage 2: add the new client as a child agent to the scene TeleportSceneClient = new TestClient(newAgent, TeleportTargetScene); - TeleportTargetScene.AddNewClient(TeleportSceneClient); + TeleportTargetScene.AddNewClient(TeleportSceneClient); } - + public virtual void SendRegionTeleport(ulong regionHandle, byte simAccess, IPEndPoint regionExternalEndPoint, uint locationID, uint flags, string capsURL) - { + { m_log.DebugFormat("[TEST CLIENT]: Received SendRegionTeleport"); - + CapsSeedUrl = capsURL; - + TeleportSceneClient.CompleteMovement(); - //TeleportTargetScene.AgentCrossing(newAgent.AgentID, new Vector3(90, 90, 90), false); + //TeleportTargetScene.AgentCrossing(newAgent.AgentID, new Vector3(90, 90, 90), false); } public virtual void SendTeleportFailed(string reason) { m_log.DebugFormat("[TEST CLIENT]: Teleport failed with reason {0}", reason); - } + } public virtual void CrossRegion(ulong newRegionHandle, Vector3 pos, Vector3 lookAt, IPEndPoint newRegionExternalEndPoint, string capsURL) { + // This is supposed to send a packet to the client telling it's ready to start region crossing. + // Instead I will just signal I'm ready, mimicking the communication behavior. + // It's ugly, but avoids needless communication setup. This is used in ScenePresenceTests.cs. + // Arthur V. + + wh.Set(); } public virtual void SendMapBlock(List mapBlocks, uint flag) @@ -845,7 +853,7 @@ namespace OpenSim.Tests.Common.Mock public void Start() { } - + public void Stop() { } diff --git a/OpenSim/Tests/Common/Setup/SceneSetupHelpers.cs b/OpenSim/Tests/Common/Setup/SceneSetupHelpers.cs index b52c081..bcc9426 100644 --- a/OpenSim/Tests/Common/Setup/SceneSetupHelpers.cs +++ b/OpenSim/Tests/Common/Setup/SceneSetupHelpers.cs @@ -40,12 +40,12 @@ using OpenSim.Region.CoreModules.Agent.Capabilities; using OpenSim.Tests.Common.Mock; namespace OpenSim.Tests.Common.Setup -{ +{ /// /// Helpers for setting up scenes. /// public class SceneSetupHelpers - { + { /// /// Set up a test scene /// @@ -54,7 +54,7 @@ namespace OpenSim.Tests.Common.Setup { return SetupScene("Unit test region", UUID.Random(), 1000, 1000, new TestCommunicationsManager()); } - + /// /// Set up a test scene /// @@ -69,32 +69,32 @@ namespace OpenSim.Tests.Common.Setup RegionInfo regInfo = new RegionInfo(x, y, new IPEndPoint(IPAddress.Loopback, 9000), "127.0.0.1"); regInfo.RegionName = name; regInfo.RegionID = id; - + AgentCircuitManager acm = new AgentCircuitManager(); SceneCommunicationService scs = new SceneCommunicationService(cm); - - StorageManager sm = new StorageManager("OpenSim.Data.Null.dll", "", ""); + + StorageManager sm = new StorageManager("OpenSim.Data.Null.dll", "", ""); IConfigSource configSource = new IniConfigSource(); - + TestScene testScene = new TestScene( regInfo, acm, cm, scs, sm, null, false, false, false, configSource, null); - + IRegionModule capsModule = new CapabilitiesModule(); capsModule.Initialise(testScene, new IniConfigSource()); - testScene.AddModule(capsModule.Name, capsModule); - testScene.SetModuleInterfaces(); - + testScene.AddModule(capsModule.Name, capsModule); + testScene.SetModuleInterfaces(); + testScene.LandChannel = new TestLandChannel(); testScene.LoadWorldMap(); - + PhysicsPluginManager physicsPluginManager = new PhysicsPluginManager(); physicsPluginManager.LoadPluginsFromAssembly("Physics/OpenSim.Region.Physics.BasicPhysicsPlugin.dll"); - testScene.PhysicsScene - = physicsPluginManager.GetPhysicsScene("basicphysics", "ZeroMesher", configSource, "test"); - + testScene.PhysicsScene + = physicsPluginManager.GetPhysicsScene("basicphysics", "ZeroMesher", configSource, "test"); + return testScene; - } - + } + /// /// Setup modules for a scene using their default settings. /// @@ -102,9 +102,9 @@ namespace OpenSim.Tests.Common.Setup /// public static void SetupSceneModules(Scene scene, params IRegionModule[] modules) { - SetupSceneModules(scene, null, modules); - } - + SetupSceneModules(scene, null, modules); + } + /// /// Setup modules for a scene. /// @@ -115,13 +115,13 @@ namespace OpenSim.Tests.Common.Setup { foreach (IRegionModule module in modules) { - module.Initialise(scene, config); + module.Initialise(scene, config); scene.AddModule(module.Name, module); } - - scene.SetModuleInterfaces(); + + scene.SetModuleInterfaces(); } - + /// /// Generate some standard agent connection data. /// @@ -130,7 +130,7 @@ namespace OpenSim.Tests.Common.Setup public static AgentCircuitData GenerateAgentData(UUID agentId) { string firstName = "testfirstname"; - + AgentCircuitData agentData = new AgentCircuitData(); agentData.AgentID = agentId; agentData.firstname = firstName; @@ -142,10 +142,10 @@ namespace OpenSim.Tests.Common.Setup agentData.InventoryFolder = UUID.Zero; agentData.startpos = Vector3.Zero; agentData.CapsPath = "http://wibble.com"; - + return agentData; } - + /// /// Add a root agent where the details of the agent connection (apart from the id) are unimportant for the test /// @@ -153,55 +153,58 @@ namespace OpenSim.Tests.Common.Setup /// /// public static TestClient AddRootAgent(Scene scene, UUID agentId) - { - return AddRootAgent(scene, GenerateAgentData(agentId)); - } - + { + return AddRootAgent(scene, GenerateAgentData(agentId)); + } + /// - /// Add a root agent. + /// Add a root agent. /// - /// + /// /// This function - /// + /// /// 1) Tells the scene that an agent is coming. Normally, the login service (local if standalone, from the /// userserver if grid) would give initial login data back to the client and separately tell the scene that the /// agent was coming. - /// + /// /// 2) Connects the agent with the scene - /// + /// /// This function performs actions equivalent with notifying the scene that an agent is /// coming and then actually connecting the agent to the scene. The one step missed out is the very first - /// + /// /// /// - /// + /// public static TestClient AddRootAgent(Scene scene, AgentCircuitData agentData) - { - // We emulate the proper login sequence here by doing things in three stages + { + // We emulate the proper login sequence here by doing things in three stages // Stage 1: simulate login by telling the scene to expect a new user connection scene.NewUserConnection(agentData); - + // Stage 2: add the new client as a child agent to the scene TestClient client = new TestClient(agentData, scene); scene.AddNewClient(client); - + // Stage 3: Invoke agent crossing, which converts the child agent into a root agent (with appearance, // inventory, etc.) - scene.AgentCrossing(agentData.AgentID, new Vector3(90, 90, 90), false); - - return client; + //scene.AgentCrossing(agentData.AgentID, new Vector3(90, 90, 90), false); OBSOLETE + + ScenePresence scp = scene.GetScenePresence(agentData.AgentID); + scp.MakeRootAgent(new Vector3(90,90,90), true); + + return client; } /// /// Add a test object /// /// - /// + /// public static SceneObjectPart AddSceneObject(Scene scene) { return AddSceneObject(scene, "Test Object"); } - + /// /// Add a test object /// @@ -209,19 +212,19 @@ namespace OpenSim.Tests.Common.Setup /// /// public static SceneObjectPart AddSceneObject(Scene scene, string name) - { - SceneObjectPart part + { + SceneObjectPart part = new SceneObjectPart(UUID.Zero, PrimitiveBaseShape.Default, Vector3.Zero, Quaternion.Identity, Vector3.Zero); part.Name = name; - - //part.UpdatePrimFlags(false, false, true); - //part.ObjectFlags |= (uint)PrimFlags.Phantom; + + //part.UpdatePrimFlags(false, false, true); + //part.ObjectFlags |= (uint)PrimFlags.Phantom; scene.AddNewSceneObject(new SceneObjectGroup(part), false); - + return part; } - + /// /// Delete a scene object asynchronously /// @@ -238,7 +241,7 @@ namespace OpenSim.Tests.Common.Setup sogd.Enabled = false; scene.DeRezObject(client, part.LocalId, UUID.Zero, action, destinationId); - sogd.InventoryDeQueueAndDelete(); + sogd.InventoryDeQueueAndDelete(); } } } -- cgit v1.1