ScenePresenceAgentTests.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  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 System.Text;
  31. using System.Threading;
  32. using System.Timers;
  33. using Timer = System.Timers.Timer;
  34. using Nini.Config;
  35. using NUnit.Framework;
  36. using OpenMetaverse;
  37. using OpenSim.Framework;
  38. using OpenSim.Framework.Communications;
  39. using OpenSim.Region.Framework.Scenes;
  40. using OpenSim.Region.Framework.Interfaces;
  41. using OpenSim.Region.ClientStack.Linden;
  42. using OpenSim.Region.CoreModules.Framework.EntityTransfer;
  43. using OpenSim.Region.CoreModules.World.Serialiser;
  44. using OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation;
  45. using OpenSim.Tests.Common;
  46. using GridRegion = OpenSim.Services.Interfaces.GridRegion;
  47. namespace OpenSim.Region.Framework.Scenes.Tests
  48. {
  49. /// <summary>
  50. /// Scene presence tests
  51. /// </summary>
  52. [TestFixture]
  53. public class ScenePresenceAgentTests : OpenSimTestCase
  54. {
  55. // public Scene scene, scene2, scene3;
  56. // public UUID agent1, agent2, agent3;
  57. // public static Random random;
  58. // public ulong region1, region2, region3;
  59. // public AgentCircuitData acd1;
  60. // public TestClient testclient;
  61. // [TestFixtureSetUp]
  62. // public void Init()
  63. // {
  64. //// TestHelpers.InMethod();
  65. ////
  66. //// SceneHelpers sh = new SceneHelpers();
  67. ////
  68. //// scene = sh.SetupScene("Neighbour x", UUID.Random(), 1000, 1000);
  69. //// scene2 = sh.SetupScene("Neighbour x+1", UUID.Random(), 1001, 1000);
  70. //// scene3 = sh.SetupScene("Neighbour x-1", UUID.Random(), 999, 1000);
  71. ////
  72. //// ISharedRegionModule interregionComms = new LocalSimulationConnectorModule();
  73. //// interregionComms.Initialise(new IniConfigSource());
  74. //// interregionComms.PostInitialise();
  75. //// SceneHelpers.SetupSceneModules(scene, new IniConfigSource(), interregionComms);
  76. //// SceneHelpers.SetupSceneModules(scene2, new IniConfigSource(), interregionComms);
  77. //// SceneHelpers.SetupSceneModules(scene3, new IniConfigSource(), interregionComms);
  78. //
  79. //// agent1 = UUID.Random();
  80. //// agent2 = UUID.Random();
  81. //// agent3 = UUID.Random();
  82. //
  83. //// region1 = scene.RegionInfo.RegionHandle;
  84. //// region2 = scene2.RegionInfo.RegionHandle;
  85. //// region3 = scene3.RegionInfo.RegionHandle;
  86. // }
  87. [Test]
  88. public void TestCreateRootScenePresence()
  89. {
  90. TestHelpers.InMethod();
  91. // TestHelpers.EnableLogging();
  92. UUID spUuid = TestHelpers.ParseTail(0x1);
  93. TestScene scene = new SceneHelpers().SetupScene();
  94. SceneHelpers.AddScenePresence(scene, spUuid);
  95. Assert.That(scene.AuthenticateHandler.GetAgentCircuitData(spUuid), Is.Not.Null);
  96. Assert.That(scene.AuthenticateHandler.GetAgentCircuits().Count, Is.EqualTo(1));
  97. ScenePresence sp = scene.GetScenePresence(spUuid);
  98. Assert.That(sp, Is.Not.Null);
  99. Assert.That(sp.IsChildAgent, Is.False);
  100. Assert.That(sp.UUID, Is.EqualTo(spUuid));
  101. Assert.That(scene.GetScenePresences().Count, Is.EqualTo(1));
  102. }
  103. /// <summary>
  104. /// Test that duplicate complete movement calls are ignored.
  105. /// </summary>
  106. /// <remarks>
  107. /// If duplicate calls are not ignored then there is a risk of race conditions or other unexpected effects.
  108. /// </remarks>
  109. [Test]
  110. public void TestDupeCompleteMovementCalls()
  111. {
  112. TestHelpers.InMethod();
  113. // TestHelpers.EnableLogging();
  114. UUID spUuid = TestHelpers.ParseTail(0x1);
  115. TestScene scene = new SceneHelpers().SetupScene();
  116. int makeRootAgentEvents = 0;
  117. scene.EventManager.OnMakeRootAgent += spi => makeRootAgentEvents++;
  118. ScenePresence sp = SceneHelpers.AddScenePresence(scene, spUuid);
  119. Assert.That(makeRootAgentEvents, Is.EqualTo(1));
  120. // Normally these would be invoked by a CompleteMovement message coming in to the UDP stack. But for
  121. // convenience, here we will invoke it manually.
  122. sp.CompleteMovement(sp.ControllingClient, true);
  123. Assert.That(makeRootAgentEvents, Is.EqualTo(1));
  124. // Check rest of exepcted parameters.
  125. Assert.That(scene.AuthenticateHandler.GetAgentCircuitData(spUuid), Is.Not.Null);
  126. Assert.That(scene.AuthenticateHandler.GetAgentCircuits().Count, Is.EqualTo(1));
  127. Assert.That(sp.IsChildAgent, Is.False);
  128. Assert.That(sp.UUID, Is.EqualTo(spUuid));
  129. Assert.That(scene.GetScenePresences().Count, Is.EqualTo(1));
  130. }
  131. [Test]
  132. public void TestCreateDuplicateRootScenePresence()
  133. {
  134. TestHelpers.InMethod();
  135. // TestHelpers.EnableLogging();
  136. UUID spUuid = TestHelpers.ParseTail(0x1);
  137. // The etm is only invoked by this test to check whether an agent is still in transit if there is a dupe
  138. EntityTransferModule etm = new EntityTransferModule();
  139. IConfigSource config = new IniConfigSource();
  140. IConfig modulesConfig = config.AddConfig("Modules");
  141. modulesConfig.Set("EntityTransferModule", etm.Name);
  142. IConfig entityTransferConfig = config.AddConfig("EntityTransfer");
  143. // In order to run a single threaded regression test we do not want the entity transfer module waiting
  144. // for a callback from the destination scene before removing its avatar data.
  145. entityTransferConfig.Set("wait_for_callback", false);
  146. TestScene scene = new SceneHelpers().SetupScene();
  147. SceneHelpers.SetupSceneModules(scene, config, etm);
  148. SceneHelpers.AddScenePresence(scene, spUuid);
  149. SceneHelpers.AddScenePresence(scene, spUuid);
  150. Assert.That(scene.AuthenticateHandler.GetAgentCircuitData(spUuid), Is.Not.Null);
  151. Assert.That(scene.AuthenticateHandler.GetAgentCircuits().Count, Is.EqualTo(1));
  152. ScenePresence sp = scene.GetScenePresence(spUuid);
  153. Assert.That(sp, Is.Not.Null);
  154. Assert.That(sp.IsChildAgent, Is.False);
  155. Assert.That(sp.UUID, Is.EqualTo(spUuid));
  156. }
  157. [Test]
  158. public void TestCloseClient()
  159. {
  160. TestHelpers.InMethod();
  161. // TestHelpers.EnableLogging();
  162. TestScene scene = new SceneHelpers().SetupScene();
  163. ScenePresence sp = SceneHelpers.AddScenePresence(scene, TestHelpers.ParseTail(0x1));
  164. scene.CloseAgent(sp.UUID, false);
  165. Assert.That(scene.GetScenePresence(sp.UUID), Is.Null);
  166. Assert.That(scene.AuthenticateHandler.GetAgentCircuitData(sp.UUID), Is.Null);
  167. Assert.That(scene.AuthenticateHandler.GetAgentCircuits().Count, Is.EqualTo(0));
  168. // TestHelpers.DisableLogging();
  169. }
  170. [Test]
  171. public void TestCreateChildScenePresence()
  172. {
  173. TestHelpers.InMethod();
  174. // log4net.Config.XmlConfigurator.Configure();
  175. LocalSimulationConnectorModule lsc = new LocalSimulationConnectorModule();
  176. IConfigSource configSource = new IniConfigSource();
  177. IConfig config = configSource.AddConfig("Modules");
  178. config.Set("SimulationServices", "LocalSimulationConnectorModule");
  179. SceneHelpers sceneHelpers = new SceneHelpers();
  180. TestScene scene = sceneHelpers.SetupScene();
  181. SceneHelpers.SetupSceneModules(scene, configSource, lsc);
  182. UUID agentId = TestHelpers.ParseTail(0x01);
  183. AgentCircuitData acd = SceneHelpers.GenerateAgentData(agentId);
  184. acd.child = true;
  185. GridRegion region = scene.GridService.GetRegionByName(UUID.Zero, scene.RegionInfo.RegionName);
  186. string reason;
  187. // *** This is the first stage, when a neighbouring region is told that a viewer is about to try and
  188. // establish a child scene presence. We pass in the circuit code that the client has to connect with ***
  189. // XXX: ViaLogin may not be correct here.
  190. scene.SimulationService.CreateAgent(null, region, acd, (uint)TeleportFlags.ViaLogin, out reason);
  191. Assert.That(scene.AuthenticateHandler.GetAgentCircuitData(agentId), Is.Not.Null);
  192. Assert.That(scene.AuthenticateHandler.GetAgentCircuits().Count, Is.EqualTo(1));
  193. // There's no scene presence yet since only an agent circuit has been established.
  194. Assert.That(scene.GetScenePresence(agentId), Is.Null);
  195. // *** This is the second stage, where the client established a child agent/scene presence using the
  196. // circuit code given to the scene in stage 1 ***
  197. TestClient client = new TestClient(acd, scene);
  198. scene.AddNewAgent(client, PresenceType.User);
  199. Assert.That(scene.AuthenticateHandler.GetAgentCircuitData(agentId), Is.Not.Null);
  200. Assert.That(scene.AuthenticateHandler.GetAgentCircuits().Count, Is.EqualTo(1));
  201. ScenePresence sp = scene.GetScenePresence(agentId);
  202. Assert.That(sp, Is.Not.Null);
  203. Assert.That(sp.UUID, Is.EqualTo(agentId));
  204. Assert.That(sp.IsChildAgent, Is.True);
  205. }
  206. /// <summary>
  207. /// Test that if a root agent logs into a region, a child agent is also established in the neighbouring region
  208. /// </summary>
  209. /// <remarks>
  210. /// Please note that unlike the other tests here, this doesn't rely on anything set up in the instance fields.
  211. /// INCOMPLETE
  212. /// </remarks>
  213. [Test]
  214. public void TestChildAgentEstablishedInNeighbour()
  215. {
  216. TestHelpers.InMethod();
  217. // log4net.Config.XmlConfigurator.Configure();
  218. // UUID agent1Id = UUID.Parse("00000000-0000-0000-0000-000000000001");
  219. TestScene myScene1 = new SceneHelpers().SetupScene("Neighbour y", UUID.Random(), 1000, 1000);
  220. TestScene myScene2 = new SceneHelpers().SetupScene("Neighbour y + 1", UUID.Random(), 1001, 1000);
  221. IConfigSource configSource = new IniConfigSource();
  222. IConfig config = configSource.AddConfig("Startup");
  223. config.Set("serverside_object_permissions", true);
  224. config.Set("EventQueue", true);
  225. EntityTransferModule etm = new EntityTransferModule();
  226. EventQueueGetModule eqgm1 = new EventQueueGetModule();
  227. SceneHelpers.SetupSceneModules(myScene1, configSource, etm, eqgm1);
  228. EventQueueGetModule eqgm2 = new EventQueueGetModule();
  229. SceneHelpers.SetupSceneModules(myScene2, configSource, etm, eqgm2);
  230. // SceneHelpers.AddScenePresence(myScene1, agent1Id);
  231. // ScenePresence childPresence = myScene2.GetScenePresence(agent1);
  232. //
  233. // // TODO: Need to do a fair amount of work to allow synchronous establishment of child agents
  234. // Assert.That(childPresence, Is.Not.Null);
  235. // Assert.That(childPresence.IsChildAgent, Is.True);
  236. }
  237. }
  238. }