ScenePresenceAgentTests.cs 13 KB

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