* 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 <arthursv@linux.vnet.ibm.com>
GenericGridServerConcept
Sean Dague 2009-02-26 21:29:16 +00:00
parent 7b04d1da5e
commit 57ab79e331
4 changed files with 119 additions and 92 deletions

View File

@ -210,7 +210,7 @@ namespace OpenSim.Framework.Communications.Cache
} }
catch (Exception e) catch (Exception e)
{ {
m_log.Error("[ASSET CACHE]: " + e); m_log.Error("[ASSET CACHE]: " + e.ToString());
} }
} }
} }

View File

@ -29,6 +29,7 @@ using Nini.Config;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;
using System.Threading;
using NUnit.Framework; using NUnit.Framework;
using NUnit.Framework.SyntaxHelpers; using NUnit.Framework.SyntaxHelpers;
using OpenMetaverse; using OpenMetaverse;
@ -91,7 +92,7 @@ namespace OpenSim.Region.Framework.Scenes.Tests
/// <summary> /// <summary>
/// Test adding a root agent to a scene. Doesn't yet actually complete crossing the agent into the scene. /// Test adding a root agent to a scene. Doesn't yet actually complete crossing the agent into the scene.
/// </summary> /// </summary>
[Test] [Test]
public void T010_TestAddRootAgent() public void T010_TestAddRootAgent()
{ {
@ -136,9 +137,11 @@ namespace OpenSim.Region.Framework.Scenes.Tests
[Test] [Test]
public void T012_TestAddNeighbourRegion() public void T012_TestAddNeighbourRegion()
{ {
SceneSetupHelpers.AddRootAgent(scene,agent1); scene.NewUserConnection(acd1);
scene.AddNewClient(testclient);
ScenePresence presence = scene.GetScenePresence(agent1); ScenePresence presence = scene.GetScenePresence(agent1);
presence.MakeRootAgent(new Vector3(90,90,90),false);
string cap = presence.ControllingClient.RequestClientInfo().CapsPath; string cap = presence.ControllingClient.RequestClientInfo().CapsPath;
@ -195,30 +198,43 @@ namespace OpenSim.Region.Framework.Scenes.Tests
string cap = presence.ControllingClient.RequestClientInfo().CapsPath; string cap = presence.ControllingClient.RequestClientInfo().CapsPath;
presence2.AddNeighbourRegion(region1, cap); presence2.AddNeighbourRegion(region1, cap);
scene.RegisterRegionWithGrid();
scene2.RegisterRegionWithGrid();
Assert.That(presence.IsChildAgent, Is.False, "Did not start root in origin region."); Assert.That(presence.IsChildAgent, Is.False, "Did not start root in origin region.");
Assert.That(presence2.IsChildAgent, Is.True, "Is not a child on destination region."); Assert.That(presence2.IsChildAgent, Is.True, "Is not a child on destination region.");
// Cross to x+1 // Cross to x+1
presence.AbsolutePosition = new Vector3(Constants.RegionSize+1,3,100); presence.AbsolutePosition = new Vector3(Constants.RegionSize+1,3,100);
scene.RegisterRegionWithGrid();
scene2.RegisterRegionWithGrid();
presence.Update(); presence.Update();
/* With RESTComms this test needs more thinking, because of the callback
// Crossings are asynchronous EventWaitHandle wh = new EventWaitHandle (false, EventResetMode.AutoReset, "Crossing");
while (presence.IsInTransit) { };
// Mimicking communication between client and server, by waiting OK from client
// sent by TestClient.CrossRegion call. Originally, this is network comm.
wh.WaitOne();
// This is a TestClient specific method that fires OnCompleteMovementToRegion event, which
// would normally be fired after receiving the reply packet from comm. done on the last line.
testclient.CompleteMovement();
// Crossings are asynchronous
while (presence.IsInTransit) { };
Assert.That(presence.IsChildAgent, Is.True, "Did not complete region cross as expected."); Assert.That(presence.IsChildAgent, Is.True, "Did not complete region cross as expected.");
Assert.That(presence2.IsChildAgent, Is.False, "Did not receive root status after receiving agent."); Assert.That(presence2.IsChildAgent, Is.False, "Did not receive root status after receiving agent.");
// Cross Back // Cross Back
presence2.AbsolutePosition = new Vector3(-1, 3, 100); presence2.AbsolutePosition = new Vector3(-10, 3, 100);
presence2.Update(); presence2.Update();
// Crossings are asynchronous
while (presence2.IsInTransit) { }; wh.WaitOne();
testclient.CompleteMovement();
while (presence2.IsInTransit) { };
Assert.That(presence2.IsChildAgent, Is.True, "Did not return from region as expected."); Assert.That(presence2.IsChildAgent, Is.True, "Did not return from region as expected.");
Assert.That(presence.IsChildAgent, Is.False, "Presence was not made root in old region again."); Assert.That(presence.IsChildAgent, Is.False, "Presence was not made root in old region again.");
*/
} }
[Test] [Test]

View File

@ -29,6 +29,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Net; using System.Net;
using System.Reflection; using System.Reflection;
using System.Threading;
using log4net; using log4net;
using OpenMetaverse; using OpenMetaverse;
using OpenMetaverse.Packets; using OpenMetaverse.Packets;
@ -41,16 +42,17 @@ namespace OpenSim.Tests.Common.Mock
public class TestClient : IClientAPI public class TestClient : IClientAPI
{ {
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
// Mock testing variables // Mock testing variables
public List<ImageDataPacket> sentdatapkt = new List<ImageDataPacket>(); public List<ImageDataPacket> sentdatapkt = new List<ImageDataPacket>();
public List<ImagePacketPacket> sentpktpkt = new List<ImagePacketPacket>(); public List<ImagePacketPacket> sentpktpkt = new List<ImagePacketPacket>();
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 // 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 // methods on when a teleport is requested
public Scene TeleportTargetScene; public Scene TeleportTargetScene;
private TestClient TeleportSceneClient; private TestClient TeleportSceneClient;
private IScene m_scene; private IScene m_scene;
// disable warning: public events, part of the public API // disable warning: public events, part of the public API
@ -272,7 +274,7 @@ namespace OpenSim.Tests.Common.Mock
/// This agent's UUID /// This agent's UUID
/// </value> /// </value>
private UUID m_agentId; private UUID m_agentId;
/// <value> /// <value>
/// The last caps seed url that this client was given. /// The last caps seed url that this client was given.
/// </value> /// </value>
@ -363,15 +365,15 @@ namespace OpenSim.Tests.Common.Mock
{ {
set { } set { }
} }
private uint m_circuitCode; private uint m_circuitCode;
public uint CircuitCode public uint CircuitCode
{ {
get { return m_circuitCode; } get { return m_circuitCode; }
set { m_circuitCode = value; } set { m_circuitCode = value; }
} }
/// <summary> /// <summary>
/// Constructor /// Constructor
/// </summary> /// </summary>
@ -386,7 +388,7 @@ namespace OpenSim.Tests.Common.Mock
m_scene = scene; m_scene = scene;
CapsSeedUrl = agentData.CapsPath; CapsSeedUrl = agentData.CapsPath;
} }
/// <summary> /// <summary>
/// Attempt a teleport to the given region. /// Attempt a teleport to the given region.
/// </summary> /// </summary>
@ -395,9 +397,9 @@ namespace OpenSim.Tests.Common.Mock
/// <param name="lookAt"></param> /// <param name="lookAt"></param>
public void Teleport(ulong regionHandle, Vector3 position, Vector3 lookAt) public void Teleport(ulong regionHandle, Vector3 position, Vector3 lookAt)
{ {
OnTeleportLocationRequest(this, regionHandle, position, lookAt, 16); OnTeleportLocationRequest(this, regionHandle, position, lookAt, 16);
} }
public void CompleteMovement() public void CompleteMovement()
{ {
OnCompleteMovementToRegion(); OnCompleteMovementToRegion();
@ -501,46 +503,52 @@ namespace OpenSim.Tests.Common.Mock
agentData.child = false; agentData.child = false;
agentData.firstname = m_firstName; agentData.firstname = m_firstName;
agentData.lastname = m_lastName; agentData.lastname = m_lastName;
ICapabilitiesModule capsModule = m_scene.RequestModuleInterface<ICapabilitiesModule>(); ICapabilitiesModule capsModule = m_scene.RequestModuleInterface<ICapabilitiesModule>();
agentData.CapsPath = capsModule.GetCapsPath(m_agentId); agentData.CapsPath = capsModule.GetCapsPath(m_agentId);
agentData.ChildrenCapSeeds = new Dictionary<ulong, string>(capsModule.GetChildrenSeeds(m_agentId)); agentData.ChildrenCapSeeds = new Dictionary<ulong, string>(capsModule.GetChildrenSeeds(m_agentId));
return agentData; return agentData;
} }
public virtual void InformClientOfNeighbour(ulong neighbourHandle, IPEndPoint neighbourExternalEndPoint) public virtual void InformClientOfNeighbour(ulong neighbourHandle, IPEndPoint neighbourExternalEndPoint)
{ {
m_log.DebugFormat("[TEST CLIENT]: Processing inform client of neighbour"); 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 // 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). // 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 // Stage 2: add the new client as a child agent to the scene
TeleportSceneClient = new TestClient(newAgent, TeleportTargetScene); TeleportSceneClient = new TestClient(newAgent, TeleportTargetScene);
TeleportTargetScene.AddNewClient(TeleportSceneClient); TeleportTargetScene.AddNewClient(TeleportSceneClient);
} }
public virtual void SendRegionTeleport(ulong regionHandle, byte simAccess, IPEndPoint regionExternalEndPoint, public virtual void SendRegionTeleport(ulong regionHandle, byte simAccess, IPEndPoint regionExternalEndPoint,
uint locationID, uint flags, string capsURL) uint locationID, uint flags, string capsURL)
{ {
m_log.DebugFormat("[TEST CLIENT]: Received SendRegionTeleport"); m_log.DebugFormat("[TEST CLIENT]: Received SendRegionTeleport");
CapsSeedUrl = capsURL; CapsSeedUrl = capsURL;
TeleportSceneClient.CompleteMovement(); 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) public virtual void SendTeleportFailed(string reason)
{ {
m_log.DebugFormat("[TEST CLIENT]: Teleport failed with reason {0}", reason); m_log.DebugFormat("[TEST CLIENT]: Teleport failed with reason {0}", reason);
} }
public virtual void CrossRegion(ulong newRegionHandle, Vector3 pos, Vector3 lookAt, public virtual void CrossRegion(ulong newRegionHandle, Vector3 pos, Vector3 lookAt,
IPEndPoint newRegionExternalEndPoint, string capsURL) 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<MapBlockData> mapBlocks, uint flag) public virtual void SendMapBlock(List<MapBlockData> mapBlocks, uint flag)
@ -845,7 +853,7 @@ namespace OpenSim.Tests.Common.Mock
public void Start() public void Start()
{ {
} }
public void Stop() public void Stop()
{ {
} }

View File

@ -40,12 +40,12 @@ using OpenSim.Region.CoreModules.Agent.Capabilities;
using OpenSim.Tests.Common.Mock; using OpenSim.Tests.Common.Mock;
namespace OpenSim.Tests.Common.Setup namespace OpenSim.Tests.Common.Setup
{ {
/// <summary> /// <summary>
/// Helpers for setting up scenes. /// Helpers for setting up scenes.
/// </summary> /// </summary>
public class SceneSetupHelpers public class SceneSetupHelpers
{ {
/// <summary> /// <summary>
/// Set up a test scene /// Set up a test scene
/// </summary> /// </summary>
@ -54,7 +54,7 @@ namespace OpenSim.Tests.Common.Setup
{ {
return SetupScene("Unit test region", UUID.Random(), 1000, 1000, new TestCommunicationsManager()); return SetupScene("Unit test region", UUID.Random(), 1000, 1000, new TestCommunicationsManager());
} }
/// <summary> /// <summary>
/// Set up a test scene /// Set up a test scene
/// </summary> /// </summary>
@ -69,32 +69,32 @@ namespace OpenSim.Tests.Common.Setup
RegionInfo regInfo = new RegionInfo(x, y, new IPEndPoint(IPAddress.Loopback, 9000), "127.0.0.1"); RegionInfo regInfo = new RegionInfo(x, y, new IPEndPoint(IPAddress.Loopback, 9000), "127.0.0.1");
regInfo.RegionName = name; regInfo.RegionName = name;
regInfo.RegionID = id; regInfo.RegionID = id;
AgentCircuitManager acm = new AgentCircuitManager(); AgentCircuitManager acm = new AgentCircuitManager();
SceneCommunicationService scs = new SceneCommunicationService(cm); 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(); IConfigSource configSource = new IniConfigSource();
TestScene testScene = new TestScene( TestScene testScene = new TestScene(
regInfo, acm, cm, scs, sm, null, false, false, false, configSource, null); regInfo, acm, cm, scs, sm, null, false, false, false, configSource, null);
IRegionModule capsModule = new CapabilitiesModule(); IRegionModule capsModule = new CapabilitiesModule();
capsModule.Initialise(testScene, new IniConfigSource()); capsModule.Initialise(testScene, new IniConfigSource());
testScene.AddModule(capsModule.Name, capsModule); testScene.AddModule(capsModule.Name, capsModule);
testScene.SetModuleInterfaces(); testScene.SetModuleInterfaces();
testScene.LandChannel = new TestLandChannel(); testScene.LandChannel = new TestLandChannel();
testScene.LoadWorldMap(); testScene.LoadWorldMap();
PhysicsPluginManager physicsPluginManager = new PhysicsPluginManager(); PhysicsPluginManager physicsPluginManager = new PhysicsPluginManager();
physicsPluginManager.LoadPluginsFromAssembly("Physics/OpenSim.Region.Physics.BasicPhysicsPlugin.dll"); physicsPluginManager.LoadPluginsFromAssembly("Physics/OpenSim.Region.Physics.BasicPhysicsPlugin.dll");
testScene.PhysicsScene testScene.PhysicsScene
= physicsPluginManager.GetPhysicsScene("basicphysics", "ZeroMesher", configSource, "test"); = physicsPluginManager.GetPhysicsScene("basicphysics", "ZeroMesher", configSource, "test");
return testScene; return testScene;
} }
/// <summary> /// <summary>
/// Setup modules for a scene using their default settings. /// Setup modules for a scene using their default settings.
/// </summary> /// </summary>
@ -102,9 +102,9 @@ namespace OpenSim.Tests.Common.Setup
/// <param name="modules"></param> /// <param name="modules"></param>
public static void SetupSceneModules(Scene scene, params IRegionModule[] modules) public static void SetupSceneModules(Scene scene, params IRegionModule[] modules)
{ {
SetupSceneModules(scene, null, modules); SetupSceneModules(scene, null, modules);
} }
/// <summary> /// <summary>
/// Setup modules for a scene. /// Setup modules for a scene.
/// </summary> /// </summary>
@ -115,13 +115,13 @@ namespace OpenSim.Tests.Common.Setup
{ {
foreach (IRegionModule module in modules) foreach (IRegionModule module in modules)
{ {
module.Initialise(scene, config); module.Initialise(scene, config);
scene.AddModule(module.Name, module); scene.AddModule(module.Name, module);
} }
scene.SetModuleInterfaces(); scene.SetModuleInterfaces();
} }
/// <summary> /// <summary>
/// Generate some standard agent connection data. /// Generate some standard agent connection data.
/// </summary> /// </summary>
@ -130,7 +130,7 @@ namespace OpenSim.Tests.Common.Setup
public static AgentCircuitData GenerateAgentData(UUID agentId) public static AgentCircuitData GenerateAgentData(UUID agentId)
{ {
string firstName = "testfirstname"; string firstName = "testfirstname";
AgentCircuitData agentData = new AgentCircuitData(); AgentCircuitData agentData = new AgentCircuitData();
agentData.AgentID = agentId; agentData.AgentID = agentId;
agentData.firstname = firstName; agentData.firstname = firstName;
@ -142,10 +142,10 @@ namespace OpenSim.Tests.Common.Setup
agentData.InventoryFolder = UUID.Zero; agentData.InventoryFolder = UUID.Zero;
agentData.startpos = Vector3.Zero; agentData.startpos = Vector3.Zero;
agentData.CapsPath = "http://wibble.com"; agentData.CapsPath = "http://wibble.com";
return agentData; return agentData;
} }
/// <summary> /// <summary>
/// Add a root agent where the details of the agent connection (apart from the id) are unimportant for the test /// Add a root agent where the details of the agent connection (apart from the id) are unimportant for the test
/// </summary> /// </summary>
@ -153,55 +153,58 @@ namespace OpenSim.Tests.Common.Setup
/// <param name="agentId"></param> /// <param name="agentId"></param>
/// <returns></returns> /// <returns></returns>
public static TestClient AddRootAgent(Scene scene, UUID agentId) public static TestClient AddRootAgent(Scene scene, UUID agentId)
{ {
return AddRootAgent(scene, GenerateAgentData(agentId)); return AddRootAgent(scene, GenerateAgentData(agentId));
} }
/// <summary> /// <summary>
/// Add a root agent. /// Add a root agent.
/// </summary> /// </summary>
/// ///
/// This function /// This function
/// ///
/// 1) Tells the scene that an agent is coming. Normally, the login service (local if standalone, from the /// 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 /// userserver if grid) would give initial login data back to the client and separately tell the scene that the
/// agent was coming. /// agent was coming.
/// ///
/// 2) Connects the agent with the scene /// 2) Connects the agent with the scene
/// ///
/// This function performs actions equivalent with notifying the scene that an agent is /// 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 /// coming and then actually connecting the agent to the scene. The one step missed out is the very first
/// ///
/// <param name="scene"></param> /// <param name="scene"></param>
/// <param name="agentData"></param> /// <param name="agentData"></param>
/// <returns></returns> /// <returns></returns>
public static TestClient AddRootAgent(Scene scene, AgentCircuitData agentData) 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 // Stage 1: simulate login by telling the scene to expect a new user connection
scene.NewUserConnection(agentData); scene.NewUserConnection(agentData);
// Stage 2: add the new client as a child agent to the scene // Stage 2: add the new client as a child agent to the scene
TestClient client = new TestClient(agentData, scene); TestClient client = new TestClient(agentData, scene);
scene.AddNewClient(client); scene.AddNewClient(client);
// Stage 3: Invoke agent crossing, which converts the child agent into a root agent (with appearance, // Stage 3: Invoke agent crossing, which converts the child agent into a root agent (with appearance,
// inventory, etc.) // inventory, etc.)
scene.AgentCrossing(agentData.AgentID, new Vector3(90, 90, 90), false); //scene.AgentCrossing(agentData.AgentID, new Vector3(90, 90, 90), false); OBSOLETE
return client; ScenePresence scp = scene.GetScenePresence(agentData.AgentID);
scp.MakeRootAgent(new Vector3(90,90,90), true);
return client;
} }
/// <summary> /// <summary>
/// Add a test object /// Add a test object
/// </summary> /// </summary>
/// <param name="scene"></param> /// <param name="scene"></param>
/// <returns></returns> /// <returns></returns>
public static SceneObjectPart AddSceneObject(Scene scene) public static SceneObjectPart AddSceneObject(Scene scene)
{ {
return AddSceneObject(scene, "Test Object"); return AddSceneObject(scene, "Test Object");
} }
/// <summary> /// <summary>
/// Add a test object /// Add a test object
/// </summary> /// </summary>
@ -209,19 +212,19 @@ namespace OpenSim.Tests.Common.Setup
/// <param name="name"></param> /// <param name="name"></param>
/// <returns></returns> /// <returns></returns>
public static SceneObjectPart AddSceneObject(Scene scene, string name) public static SceneObjectPart AddSceneObject(Scene scene, string name)
{ {
SceneObjectPart part SceneObjectPart part
= new SceneObjectPart(UUID.Zero, PrimitiveBaseShape.Default, Vector3.Zero, Quaternion.Identity, Vector3.Zero); = new SceneObjectPart(UUID.Zero, PrimitiveBaseShape.Default, Vector3.Zero, Quaternion.Identity, Vector3.Zero);
part.Name = name; part.Name = name;
//part.UpdatePrimFlags(false, false, true); //part.UpdatePrimFlags(false, false, true);
//part.ObjectFlags |= (uint)PrimFlags.Phantom; //part.ObjectFlags |= (uint)PrimFlags.Phantom;
scene.AddNewSceneObject(new SceneObjectGroup(part), false); scene.AddNewSceneObject(new SceneObjectGroup(part), false);
return part; return part;
} }
/// <summary> /// <summary>
/// Delete a scene object asynchronously /// Delete a scene object asynchronously
/// </summary> /// </summary>
@ -238,7 +241,7 @@ namespace OpenSim.Tests.Common.Setup
sogd.Enabled = false; sogd.Enabled = false;
scene.DeRezObject(client, part.LocalId, UUID.Zero, action, destinationId); scene.DeRezObject(client, part.LocalId, UUID.Zero, action, destinationId);
sogd.InventoryDeQueueAndDelete(); sogd.InventoryDeQueueAndDelete();
} }
} }
} }