1
0

ScenePresenceAgentTests.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  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. }
  103. [Test]
  104. public void TestCreateDuplicateRootScenePresence()
  105. {
  106. TestHelpers.InMethod();
  107. // TestHelpers.EnableLogging();
  108. UUID spUuid = TestHelpers.ParseTail(0x1);
  109. TestScene scene = new SceneHelpers().SetupScene();
  110. SceneHelpers.AddScenePresence(scene, spUuid);
  111. SceneHelpers.AddScenePresence(scene, spUuid);
  112. Assert.That(scene.AuthenticateHandler.GetAgentCircuitData(spUuid), Is.Not.Null);
  113. Assert.That(scene.AuthenticateHandler.GetAgentCircuits().Count, Is.EqualTo(1));
  114. ScenePresence sp = scene.GetScenePresence(spUuid);
  115. Assert.That(sp, Is.Not.Null);
  116. Assert.That(sp.IsChildAgent, Is.False);
  117. Assert.That(sp.UUID, Is.EqualTo(spUuid));
  118. }
  119. [Test]
  120. public void TestCloseAgent()
  121. {
  122. TestHelpers.InMethod();
  123. // TestHelpers.EnableLogging();
  124. TestScene scene = new SceneHelpers().SetupScene();
  125. ScenePresence sp = SceneHelpers.AddScenePresence(scene, TestHelpers.ParseTail(0x1));
  126. scene.IncomingCloseAgent(sp.UUID, false);
  127. Assert.That(scene.GetScenePresence(sp.UUID), Is.Null);
  128. Assert.That(scene.AuthenticateHandler.GetAgentCircuitData(sp.UUID), Is.Null);
  129. Assert.That(scene.AuthenticateHandler.GetAgentCircuits().Count, Is.EqualTo(0));
  130. // TestHelpers.DisableLogging();
  131. }
  132. [Test]
  133. public void TestCreateChildScenePresence()
  134. {
  135. TestHelpers.InMethod();
  136. // log4net.Config.XmlConfigurator.Configure();
  137. LocalSimulationConnectorModule lsc = new LocalSimulationConnectorModule();
  138. IConfigSource configSource = new IniConfigSource();
  139. IConfig config = configSource.AddConfig("Modules");
  140. config.Set("SimulationServices", "LocalSimulationConnectorModule");
  141. SceneHelpers sceneHelpers = new SceneHelpers();
  142. TestScene scene = sceneHelpers.SetupScene();
  143. SceneHelpers.SetupSceneModules(scene, configSource, lsc);
  144. UUID agentId = TestHelpers.ParseTail(0x01);
  145. AgentCircuitData acd = SceneHelpers.GenerateAgentData(agentId);
  146. acd.child = true;
  147. GridRegion region = scene.GridService.GetRegionByName(UUID.Zero, scene.RegionInfo.RegionName);
  148. string reason;
  149. // *** This is the first stage, when a neighbouring region is told that a viewer is about to try and
  150. // establish a child scene presence. We pass in the circuit code that the client has to connect with ***
  151. // XXX: ViaLogin may not be correct here.
  152. scene.SimulationService.CreateAgent(region, acd, (uint)TeleportFlags.ViaLogin, out reason);
  153. Assert.That(scene.AuthenticateHandler.GetAgentCircuitData(agentId), Is.Not.Null);
  154. Assert.That(scene.AuthenticateHandler.GetAgentCircuits().Count, Is.EqualTo(1));
  155. // There's no scene presence yet since only an agent circuit has been established.
  156. Assert.That(scene.GetScenePresence(agentId), Is.Null);
  157. // *** This is the second stage, where the client established a child agent/scene presence using the
  158. // circuit code given to the scene in stage 1 ***
  159. TestClient client = new TestClient(acd, scene);
  160. scene.AddNewClient(client, PresenceType.User);
  161. Assert.That(scene.AuthenticateHandler.GetAgentCircuitData(agentId), Is.Not.Null);
  162. Assert.That(scene.AuthenticateHandler.GetAgentCircuits().Count, Is.EqualTo(1));
  163. ScenePresence sp = scene.GetScenePresence(agentId);
  164. Assert.That(sp, Is.Not.Null);
  165. Assert.That(sp.UUID, Is.EqualTo(agentId));
  166. Assert.That(sp.IsChildAgent, Is.True);
  167. }
  168. /// <summary>
  169. /// Test that if a root agent logs into a region, a child agent is also established in the neighbouring region
  170. /// </summary>
  171. /// <remarks>
  172. /// Please note that unlike the other tests here, this doesn't rely on anything set up in the instance fields.
  173. /// INCOMPLETE
  174. /// </remarks>
  175. [Test]
  176. public void TestChildAgentEstablishedInNeighbour()
  177. {
  178. TestHelpers.InMethod();
  179. // log4net.Config.XmlConfigurator.Configure();
  180. // UUID agent1Id = UUID.Parse("00000000-0000-0000-0000-000000000001");
  181. TestScene myScene1 = new SceneHelpers().SetupScene("Neighbour y", UUID.Random(), 1000, 1000);
  182. TestScene myScene2 = new SceneHelpers().SetupScene("Neighbour y + 1", UUID.Random(), 1001, 1000);
  183. IConfigSource configSource = new IniConfigSource();
  184. IConfig config = configSource.AddConfig("Startup");
  185. config.Set("serverside_object_permissions", true);
  186. config.Set("EventQueue", true);
  187. EntityTransferModule etm = new EntityTransferModule();
  188. EventQueueGetModule eqgm1 = new EventQueueGetModule();
  189. SceneHelpers.SetupSceneModules(myScene1, configSource, etm, eqgm1);
  190. EventQueueGetModule eqgm2 = new EventQueueGetModule();
  191. SceneHelpers.SetupSceneModules(myScene2, configSource, etm, eqgm2);
  192. // SceneHelpers.AddScenePresence(myScene1, agent1Id);
  193. // ScenePresence childPresence = myScene2.GetScenePresence(agent1);
  194. //
  195. // // TODO: Need to do a fair amount of work to allow synchronous establishment of child agents
  196. // Assert.That(childPresence, Is.Not.Null);
  197. // Assert.That(childPresence.IsChildAgent, Is.True);
  198. }
  199. // /// <summary>
  200. // /// Test adding a root agent to a scene. Doesn't yet actually complete crossing the agent into the scene.
  201. // /// </summary>
  202. // [Test]
  203. // public void T010_TestAddRootAgent()
  204. // {
  205. // TestHelpers.InMethod();
  206. //
  207. // string firstName = "testfirstname";
  208. //
  209. // AgentCircuitData agent = new AgentCircuitData();
  210. // agent.AgentID = agent1;
  211. // agent.firstname = firstName;
  212. // agent.lastname = "testlastname";
  213. // agent.SessionID = UUID.Random();
  214. // agent.SecureSessionID = UUID.Random();
  215. // agent.circuitcode = 123;
  216. // agent.BaseFolder = UUID.Zero;
  217. // agent.InventoryFolder = UUID.Zero;
  218. // agent.startpos = Vector3.Zero;
  219. // agent.CapsPath = GetRandomCapsObjectPath();
  220. // agent.ChildrenCapSeeds = new Dictionary<ulong, string>();
  221. // agent.child = true;
  222. //
  223. // scene.PresenceService.LoginAgent(agent.AgentID.ToString(), agent.SessionID, agent.SecureSessionID);
  224. //
  225. // string reason;
  226. // scene.NewUserConnection(agent, (uint)TeleportFlags.ViaLogin, out reason);
  227. // testclient = new TestClient(agent, scene);
  228. // scene.AddNewClient(testclient);
  229. //
  230. // ScenePresence presence = scene.GetScenePresence(agent1);
  231. //
  232. // Assert.That(presence, Is.Not.Null, "presence is null");
  233. // Assert.That(presence.Firstname, Is.EqualTo(firstName), "First name not same");
  234. // acd1 = agent;
  235. // }
  236. //
  237. // /// <summary>
  238. // /// Test removing an uncrossed root agent from a scene.
  239. // /// </summary>
  240. // [Test]
  241. // public void T011_TestRemoveRootAgent()
  242. // {
  243. // TestHelpers.InMethod();
  244. //
  245. // scene.RemoveClient(agent1);
  246. //
  247. // ScenePresence presence = scene.GetScenePresence(agent1);
  248. //
  249. // Assert.That(presence, Is.Null, "presence is not null");
  250. // }
  251. // I'm commenting this test because it does not represent
  252. // crossings. The Thread.Sleep's in here are not meaningful mocks,
  253. // and they sometimes fail in panda.
  254. // We need to talk in order to develop a test
  255. // that really tests region crossings. There are 3 async components,
  256. // but things are synchronous among them. So there should be
  257. // 3 threads in here.
  258. //[Test]
  259. // public void T021_TestCrossToNewRegion()
  260. // {
  261. // TestHelpers.InMethod();
  262. //
  263. // scene.RegisterRegionWithGrid();
  264. // scene2.RegisterRegionWithGrid();
  265. //
  266. // // Adding child agent to region 1001
  267. // string reason;
  268. // scene2.NewUserConnection(acd1,0, out reason);
  269. // scene2.AddNewClient(testclient, PresenceType.User);
  270. //
  271. // ScenePresence presence = scene.GetScenePresence(agent1);
  272. // presence.MakeRootAgent(new Vector3(0,unchecked(Constants.RegionSize-1),0), true);
  273. //
  274. // ScenePresence presence2 = scene2.GetScenePresence(agent1);
  275. //
  276. // // Adding neighbour region caps info to presence2
  277. //
  278. // string cap = presence.ControllingClient.RequestClientInfo().CapsPath;
  279. // presence2.AddNeighbourRegion(region1, cap);
  280. //
  281. // Assert.That(presence.IsChildAgent, Is.False, "Did not start root in origin region.");
  282. // Assert.That(presence2.IsChildAgent, Is.True, "Is not a child on destination region.");
  283. //
  284. // // Cross to x+1
  285. // presence.AbsolutePosition = new Vector3(Constants.RegionSize+1,3,100);
  286. // presence.Update();
  287. //
  288. // EventWaitHandle wh = new EventWaitHandle (false, EventResetMode.AutoReset, "Crossing");
  289. //
  290. // // Mimicking communication between client and server, by waiting OK from client
  291. // // sent by TestClient.CrossRegion call. Originally, this is network comm.
  292. // if (!wh.WaitOne(5000,false))
  293. // {
  294. // presence.Update();
  295. // if (!wh.WaitOne(8000,false))
  296. // throw new ArgumentException("1 - Timeout waiting for signal/variable.");
  297. // }
  298. //
  299. // // This is a TestClient specific method that fires OnCompleteMovementToRegion event, which
  300. // // would normally be fired after receiving the reply packet from comm. done on the last line.
  301. // testclient.CompleteMovement();
  302. //
  303. // // Crossings are asynchronous
  304. // int timer = 10;
  305. //
  306. // // Make sure cross hasn't already finished
  307. // if (!presence.IsInTransit && !presence.IsChildAgent)
  308. // {
  309. // // If not and not in transit yet, give it some more time
  310. // Thread.Sleep(5000);
  311. // }
  312. //
  313. // // Enough time, should at least be in transit by now.
  314. // while (presence.IsInTransit && timer > 0)
  315. // {
  316. // Thread.Sleep(1000);
  317. // timer-=1;
  318. // }
  319. //
  320. // Assert.That(timer,Is.GreaterThan(0),"Timed out waiting to cross 2->1.");
  321. // Assert.That(presence.IsChildAgent, Is.True, "Did not complete region cross as expected.");
  322. // Assert.That(presence2.IsChildAgent, Is.False, "Did not receive root status after receiving agent.");
  323. //
  324. // // Cross Back
  325. // presence2.AbsolutePosition = new Vector3(-10, 3, 100);
  326. // presence2.Update();
  327. //
  328. // if (!wh.WaitOne(5000,false))
  329. // {
  330. // presence2.Update();
  331. // if (!wh.WaitOne(8000,false))
  332. // throw new ArgumentException("2 - Timeout waiting for signal/variable.");
  333. // }
  334. // testclient.CompleteMovement();
  335. //
  336. // if (!presence2.IsInTransit && !presence2.IsChildAgent)
  337. // {
  338. // // If not and not in transit yet, give it some more time
  339. // Thread.Sleep(5000);
  340. // }
  341. //
  342. // // Enough time, should at least be in transit by now.
  343. // while (presence2.IsInTransit && timer > 0)
  344. // {
  345. // Thread.Sleep(1000);
  346. // timer-=1;
  347. // }
  348. //
  349. // Assert.That(timer,Is.GreaterThan(0),"Timed out waiting to cross 1->2.");
  350. // Assert.That(presence2.IsChildAgent, Is.True, "Did not return from region as expected.");
  351. // Assert.That(presence.IsChildAgent, Is.False, "Presence was not made root in old region again.");
  352. // }
  353. }
  354. }