ScenePresenceCrossingTests.cs 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSimulator Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. using System;
  28. using System.Collections.Generic;
  29. using System.Reflection;
  30. using Nini.Config;
  31. using NUnit.Framework;
  32. using OpenMetaverse;
  33. using OpenSim.Framework;
  34. using OpenSim.Framework.Communications;
  35. using OpenSim.Framework.Servers;
  36. using OpenSim.Region.Framework.Interfaces;
  37. using OpenSim.Region.CoreModules.Framework;
  38. using OpenSim.Region.CoreModules.Framework.EntityTransfer;
  39. using OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation;
  40. using OpenSim.Tests.Common;
  41. using OpenSim.Tests.Common.Mock;
  42. namespace OpenSim.Region.Framework.Scenes.Tests
  43. {
  44. [TestFixture]
  45. public class ScenePresenceCrossingTests : OpenSimTestCase
  46. {
  47. [TestFixtureSetUp]
  48. public void FixtureInit()
  49. {
  50. // Don't allow tests to be bamboozled by asynchronous events. Execute everything on the same thread.
  51. Util.FireAndForgetMethod = FireAndForgetMethod.RegressionTest;
  52. }
  53. [TestFixtureTearDown]
  54. public void TearDown()
  55. {
  56. // We must set this back afterwards, otherwise later tests will fail since they're expecting multiple
  57. // threads. Possibly, later tests should be rewritten so none of them require async stuff (which regression
  58. // tests really shouldn't).
  59. Util.FireAndForgetMethod = Util.DefaultFireAndForgetMethod;
  60. }
  61. [Test]
  62. public void TestCrossOnSameSimulator()
  63. {
  64. TestHelpers.InMethod();
  65. // TestHelpers.EnableLogging();
  66. UUID userId = TestHelpers.ParseTail(0x1);
  67. // TestEventQueueGetModule eqmA = new TestEventQueueGetModule();
  68. EntityTransferModule etmA = new EntityTransferModule();
  69. EntityTransferModule etmB = new EntityTransferModule();
  70. LocalSimulationConnectorModule lscm = new LocalSimulationConnectorModule();
  71. IConfigSource config = new IniConfigSource();
  72. IConfig modulesConfig = config.AddConfig("Modules");
  73. modulesConfig.Set("EntityTransferModule", etmA.Name);
  74. modulesConfig.Set("SimulationServices", lscm.Name);
  75. // IConfig entityTransferConfig = config.AddConfig("EntityTransfer");
  76. // In order to run a single threaded regression test we do not want the entity transfer module waiting
  77. // for a callback from the destination scene before removing its avatar data.
  78. // entityTransferConfig.Set("wait_for_callback", false);
  79. SceneHelpers sh = new SceneHelpers();
  80. TestScene sceneA = sh.SetupScene("sceneA", TestHelpers.ParseTail(0x100), 1000, 1000);
  81. TestScene sceneB = sh.SetupScene("sceneB", TestHelpers.ParseTail(0x200), 1000, 999);
  82. SceneHelpers.SetupSceneModules(new Scene[] { sceneA, sceneB }, config, lscm);
  83. SceneHelpers.SetupSceneModules(sceneA, config, new CapabilitiesModule(), etmA);
  84. // SceneHelpers.SetupSceneModules(sceneA, config, new CapabilitiesModule(), etmA, eqmA);
  85. SceneHelpers.SetupSceneModules(sceneB, config, new CapabilitiesModule(), etmB);
  86. AgentCircuitData acd = SceneHelpers.GenerateAgentData(userId);
  87. TestClient tc = new TestClient(acd, sceneA);
  88. List<TestClient> destinationTestClients = new List<TestClient>();
  89. EntityTransferHelpers.SetupInformClientOfNeighbourTriggersNeighbourClientCreate(tc, destinationTestClients);
  90. ScenePresence originalSp = SceneHelpers.AddScenePresence(sceneA, tc, acd);
  91. originalSp.AbsolutePosition = new Vector3(128, 32, 10);
  92. // originalSp.Flying = true;
  93. // Console.WriteLine("First pos {0}", originalSp.AbsolutePosition);
  94. // eqmA.ClearEvents();
  95. AgentUpdateArgs moveArgs = new AgentUpdateArgs();
  96. //moveArgs.BodyRotation = Quaternion.CreateFromEulers(Vector3.Zero);
  97. moveArgs.BodyRotation = Quaternion.CreateFromEulers(new Vector3(0, 0, (float)-(Math.PI / 2)));
  98. moveArgs.ControlFlags = (uint)AgentManager.ControlFlags.AGENT_CONTROL_AT_POS;
  99. moveArgs.SessionID = acd.SessionID;
  100. originalSp.HandleAgentUpdate(originalSp.ControllingClient, moveArgs);
  101. sceneA.Update(1);
  102. // Console.WriteLine("Second pos {0}", originalSp.AbsolutePosition);
  103. // FIXME: This is a sufficient number of updates to for the presence to reach the northern border.
  104. // But really we want to do this in a more robust way.
  105. for (int i = 0; i < 100; i++)
  106. {
  107. sceneA.Update(1);
  108. // Console.WriteLine("Pos {0}", originalSp.AbsolutePosition);
  109. }
  110. // Need to sort processing of EnableSimulator message on adding scene presences before we can test eqm
  111. // messages
  112. // Dictionary<UUID, List<TestEventQueueGetModule.Event>> eqmEvents = eqmA.Events;
  113. //
  114. // Assert.That(eqmEvents.Count, Is.EqualTo(1));
  115. // Assert.That(eqmEvents.ContainsKey(originalSp.UUID), Is.True);
  116. //
  117. // List<TestEventQueueGetModule.Event> spEqmEvents = eqmEvents[originalSp.UUID];
  118. //
  119. // Assert.That(spEqmEvents.Count, Is.EqualTo(1));
  120. // Assert.That(spEqmEvents[0].Name, Is.EqualTo("CrossRegion"));
  121. // sceneA should now only have a child agent
  122. ScenePresence spAfterCrossSceneA = sceneA.GetScenePresence(originalSp.UUID);
  123. Assert.That(spAfterCrossSceneA.IsChildAgent, Is.True);
  124. ScenePresence spAfterCrossSceneB = sceneB.GetScenePresence(originalSp.UUID);
  125. // Agent remains a child until the client triggers complete movement
  126. Assert.That(spAfterCrossSceneB.IsChildAgent, Is.True);
  127. TestClient sceneBTc = ((TestClient)spAfterCrossSceneB.ControllingClient);
  128. int agentMovementCompleteReceived = 0;
  129. sceneBTc.OnReceivedMoveAgentIntoRegion += (ri, pos, look) => agentMovementCompleteReceived++;
  130. sceneBTc.CompleteMovement();
  131. Assert.That(agentMovementCompleteReceived, Is.EqualTo(1));
  132. Assert.That(spAfterCrossSceneB.IsChildAgent, Is.False);
  133. }
  134. }
  135. }