ScenePresenceAgentTests.cs 13 KB

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