Add regression test to check that attachments in source region are deleting when an agent teleports to a neighbouring region

0.7.4.1
Justin Clark-Casey (justincc) 2012-06-26 22:16:44 +01:00
parent 340005c5bf
commit 32a4ce94f0
2 changed files with 122 additions and 20 deletions

View File

@ -38,6 +38,8 @@ using OpenMetaverse;
using OpenSim.Framework;
using OpenSim.Framework.Communications;
using OpenSim.Region.CoreModules.Avatar.Attachments;
using OpenSim.Region.CoreModules.Framework;
using OpenSim.Region.CoreModules.Framework.EntityTransfer;
using OpenSim.Region.CoreModules.Framework.InventoryAccess;
using OpenSim.Region.CoreModules.World.Serialiser;
using OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation;
@ -54,7 +56,6 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests
[TestFixture]
public class AttachmentsModuleTests
{
private Scene scene;
private AttachmentsModule m_attMod;
private ScenePresence m_presence;
@ -80,18 +81,6 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests
Util.FireAndForgetMethod = FireAndForgetMethod.None;
}
[SetUp]
public void Init()
{
IConfigSource config = new IniConfigSource();
config.AddConfig("Modules");
config.Configs["Modules"].Set("InventoryAccessModule", "BasicInventoryAccessModule");
scene = new SceneHelpers().SetupScene();
m_attMod = new AttachmentsModule();
SceneHelpers.SetupSceneModules(scene, config, m_attMod, new BasicInventoryAccessModule());
}
[TestFixtureTearDown]
public void TearDown()
{
@ -100,6 +89,19 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests
Util.FireAndForgetMethod = Util.DefaultFireAndForgetMethod;
}
private Scene CreateDefaultTestScene()
{
IConfigSource config = new IniConfigSource();
config.AddConfig("Modules");
config.Configs["Modules"].Set("InventoryAccessModule", "BasicInventoryAccessModule");
Scene scene = new SceneHelpers().SetupScene();
m_attMod = new AttachmentsModule();
SceneHelpers.SetupSceneModules(scene, config, m_attMod, new BasicInventoryAccessModule());
return scene;
}
/// <summary>
/// Creates an attachment item in the given user's inventory. Does not attach.
/// </summary>
@ -109,11 +111,13 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests
/// <returns>
/// The attachment item.
/// </returns>
/// <param name='scene'></param>
/// <param name='userId'></param>
/// <param name='attName'></param>
/// <param name='rawItemId'></param>
/// <param name='rawAssetId'></param>
private InventoryItemBase CreateAttachmentItem(UUID userId, string attName, int rawItemId, int rawAssetId)
private InventoryItemBase CreateAttachmentItem(
Scene scene, UUID userId, string attName, int rawItemId, int rawAssetId)
{
return UserInventoryHelpers.CreateInventoryItem(
scene,
@ -130,6 +134,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests
TestHelpers.InMethod();
// TestHelpers.EnableLogging();
Scene scene = CreateDefaultTestScene();
UserAccountHelpers.CreateUserWithInventory(scene, m_userId);
m_presence = SceneHelpers.AddScenePresence(scene, m_userId);
@ -171,10 +176,11 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests
TestHelpers.InMethod();
// log4net.Config.XmlConfigurator.Configure();
Scene scene = CreateDefaultTestScene();
UserAccountHelpers.CreateUserWithInventory(scene, m_userId);
m_presence = SceneHelpers.AddScenePresence(scene, m_userId);
InventoryItemBase attItem = CreateAttachmentItem(m_userId, "att", 0x10, 0x20);
InventoryItemBase attItem = CreateAttachmentItem(scene, m_userId, "att", 0x10, 0x20);
m_attMod.RezSingleAttachmentFromInventory(
m_presence, attItem.ID, (uint)AttachmentPoint.Chest);
@ -201,10 +207,11 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests
TestHelpers.InMethod();
// log4net.Config.XmlConfigurator.Configure();
Scene scene = CreateDefaultTestScene();
UserAccountHelpers.CreateUserWithInventory(scene, m_userId);
m_presence = SceneHelpers.AddScenePresence(scene, m_userId);
InventoryItemBase attItem = CreateAttachmentItem(m_userId, "att", 0x10, 0x20);
InventoryItemBase attItem = CreateAttachmentItem(scene, m_userId, "att", 0x10, 0x20);
ISceneEntity so
= m_attMod.RezSingleAttachmentFromInventory(
@ -232,10 +239,11 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests
TestHelpers.InMethod();
// log4net.Config.XmlConfigurator.Configure();
Scene scene = CreateDefaultTestScene();
UserAccountHelpers.CreateUserWithInventory(scene, m_userId);
m_presence = SceneHelpers.AddScenePresence(scene, m_userId);
InventoryItemBase attItem = CreateAttachmentItem(m_userId, "att", 0x10, 0x20);
InventoryItemBase attItem = CreateAttachmentItem(scene, m_userId, "att", 0x10, 0x20);
m_attMod.RezSingleAttachmentFromInventory(
m_presence, attItem.ID, (uint)AttachmentPoint.Chest);
@ -259,8 +267,9 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests
TestHelpers.InMethod();
// log4net.Config.XmlConfigurator.Configure();
Scene scene = CreateDefaultTestScene();
UserAccountHelpers.CreateUserWithInventory(scene, m_userId);
InventoryItemBase attItem = CreateAttachmentItem(m_userId, "att", 0x10, 0x20);
InventoryItemBase attItem = CreateAttachmentItem(scene, m_userId, "att", 0x10, 0x20);
AgentCircuitData acd = SceneHelpers.GenerateAgentData(m_userId);
acd.Appearance = new AvatarAppearance();
@ -281,8 +290,9 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests
TestHelpers.InMethod();
// log4net.Config.XmlConfigurator.Configure();
Scene scene = CreateDefaultTestScene();
UserAccountHelpers.CreateUserWithInventory(scene, m_userId);
InventoryItemBase attItem = CreateAttachmentItem(m_userId, "att", 0x10, 0x20);
InventoryItemBase attItem = CreateAttachmentItem(scene, m_userId, "att", 0x10, 0x20);
AgentCircuitData acd = SceneHelpers.GenerateAgentData(m_userId);
acd.Appearance = new AvatarAppearance();
@ -314,8 +324,9 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests
{
TestHelpers.InMethod();
Scene scene = CreateDefaultTestScene();
UserAccountHelpers.CreateUserWithInventory(scene, m_userId);
InventoryItemBase attItem = CreateAttachmentItem(m_userId, "att", 0x10, 0x20);
InventoryItemBase attItem = CreateAttachmentItem(scene, m_userId, "att", 0x10, 0x20);
AgentCircuitData acd = SceneHelpers.GenerateAgentData(m_userId);
acd.Appearance = new AvatarAppearance();
@ -332,6 +343,92 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests
Assert.That(attSo.RootPart.AttachedPos, Is.EqualTo(newPosition));
}
[Test]
public void TestSameSimulatorNeighbouringRegionsTeleport()
{
TestHelpers.InMethod();
// TestHelpers.EnableLogging();
AttachmentsModule attModA = new AttachmentsModule();
AttachmentsModule attModB = new AttachmentsModule();
EntityTransferModule etmA = new EntityTransferModule();
EntityTransferModule etmB = new EntityTransferModule();
LocalSimulationConnectorModule lscm = new LocalSimulationConnectorModule();
IConfigSource config = new IniConfigSource();
IConfig modulesConfig = config.AddConfig("Modules");
modulesConfig.Set("EntityTransferModule", etmA.Name);
modulesConfig.Set("SimulationServices", lscm.Name);
IConfig entityTransferConfig = config.AddConfig("EntityTransfer");
// In order to run a single threaded regression test we do not want the entity transfer module waiting
// for a callback from the destination scene before removing its avatar data.
entityTransferConfig.Set("wait_for_callback", false);
SceneHelpers sh = new SceneHelpers();
TestScene sceneA = sh.SetupScene("sceneA", TestHelpers.ParseTail(0x100), 1000, 1000);
TestScene sceneB = sh.SetupScene("sceneB", TestHelpers.ParseTail(0x200), 1001, 1000);
SceneHelpers.SetupSceneModules(new Scene[] { sceneA, sceneB }, config, lscm);
SceneHelpers.SetupSceneModules(
sceneA, config, new CapabilitiesModule(), etmA, attModA, new BasicInventoryAccessModule());
SceneHelpers.SetupSceneModules(
sceneB, config, new CapabilitiesModule(), etmB, attModB, new BasicInventoryAccessModule());
UserAccountHelpers.CreateUserWithInventory(sceneA, m_userId);
ScenePresence beforeTeleportSp = SceneHelpers.AddScenePresence(sceneA, m_userId, sh.SceneManager);
beforeTeleportSp.AbsolutePosition = new Vector3(30, 31, 32);
InventoryItemBase attItem = CreateAttachmentItem(sceneA, m_userId, "att", 0x10, 0x20);
m_attMod.RezSingleAttachmentFromInventory(
beforeTeleportSp, attItem.ID, (uint)AttachmentPoint.Chest);
Vector3 teleportPosition = new Vector3(10, 11, 12);
Vector3 teleportLookAt = new Vector3(20, 21, 22);
sceneA.RequestTeleportLocation(
beforeTeleportSp.ControllingClient,
sceneB.RegionInfo.RegionHandle,
teleportPosition,
teleportLookAt,
(uint)TeleportFlags.ViaLocation);
((TestClient)beforeTeleportSp.ControllingClient).CompleteTeleportClientSide();
// Check attachments have made it into sceneB
ScenePresence afterTeleportSceneBSp = sceneB.GetScenePresence(m_userId);
// This is appearance data, as opposed to actually rezzed attachments
List<AvatarAttachment> sceneBAttachments = afterTeleportSceneBSp.Appearance.GetAttachments();
Assert.That(sceneBAttachments.Count, Is.EqualTo(1));
Assert.That(sceneBAttachments[0].AttachPoint, Is.EqualTo((int)AttachmentPoint.Chest));
Assert.That(sceneBAttachments[0].ItemID, Is.EqualTo(attItem.ID));
Assert.That(sceneBAttachments[0].AssetID, Is.EqualTo(attItem.AssetID));
Assert.That(afterTeleportSceneBSp.Appearance.GetAttachpoint(attItem.ID), Is.EqualTo((int)AttachmentPoint.Chest));
// This is the actual attachment
List<SceneObjectGroup> actualSceneBAttachments = afterTeleportSceneBSp.GetAttachments();
Assert.That(actualSceneBAttachments.Count, Is.EqualTo(1));
SceneObjectGroup actualSceneBAtt = actualSceneBAttachments[0];
Assert.That(actualSceneBAtt.Name, Is.EqualTo(attItem.Name));
Assert.That(actualSceneBAtt.AttachmentPoint, Is.EqualTo((uint)AttachmentPoint.Chest));
// Check attachments have been removed from sceneA
ScenePresence afterTeleportSceneASp = sceneA.GetScenePresence(m_userId);
// Since this is appearance data, it is still present on the child avatar!
List<AvatarAttachment> sceneAAttachments = afterTeleportSceneASp.Appearance.GetAttachments();
Assert.That(sceneAAttachments.Count, Is.EqualTo(1));
Assert.That(afterTeleportSceneASp.Appearance.GetAttachpoint(attItem.ID), Is.EqualTo((int)AttachmentPoint.Chest));
// This is the actual attachment, which should no longer exist
List<SceneObjectGroup> actualSceneAAttachments = afterTeleportSceneASp.GetAttachments();
Assert.That(actualSceneAAttachments.Count, Is.EqualTo(0));
// TestHelpers.DisableLogging();
}
// I'm commenting this test because scene setup NEEDS InventoryService to
// be non-null
//[Test]

View File

@ -709,6 +709,11 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
agent.CallbackURI, region.RegionName);
}
/// <summary>
/// Clean up operations once an agent has moved away through cross or teleport.
/// </summary>
/// <param name='sp'></param>
/// <param name='logout'></param>
protected virtual void AgentHasMovedAway(ScenePresence sp, bool logout)
{
if (sp.Scene.AttachmentsModule != null)