aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceAgentTests.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Framework/Scenes/Tests/ScenePresenceAgentTests.cs')
-rw-r--r--OpenSim/Region/Framework/Scenes/Tests/ScenePresenceAgentTests.cs373
1 files changed, 373 insertions, 0 deletions
diff --git a/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceAgentTests.cs b/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceAgentTests.cs
new file mode 100644
index 0000000..ce9d418
--- /dev/null
+++ b/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceAgentTests.cs
@@ -0,0 +1,373 @@
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
28using System;
29using System.Collections.Generic;
30using System.Reflection;
31using System.Text;
32using System.Threading;
33using System.Timers;
34using Timer=System.Timers.Timer;
35using Nini.Config;
36using NUnit.Framework;
37using OpenMetaverse;
38using OpenSim.Framework;
39using OpenSim.Framework.Communications;
40using OpenSim.Region.Framework.Scenes;
41using OpenSim.Region.Framework.Interfaces;
42using OpenSim.Region.CoreModules.Framework.EntityTransfer;
43using OpenSim.Region.CoreModules.World.Serialiser;
44using OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation;
45using OpenSim.Tests.Common;
46using OpenSim.Tests.Common.Mock;
47
48namespace OpenSim.Region.Framework.Scenes.Tests
49{
50 /// <summary>
51 /// Scene presence tests
52 /// </summary>
53 [TestFixture]
54 public class ScenePresenceAgentTests
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 SceneObjectGroup sog1, sog2, sog3;
62 public TestClient testclient;
63
64 [TestFixtureSetUp]
65 public void Init()
66 {
67 TestHelpers.InMethod();
68
69 scene = SceneHelpers.SetupScene("Neighbour x", UUID.Random(), 1000, 1000);
70 scene2 = SceneHelpers.SetupScene("Neighbour x+1", UUID.Random(), 1001, 1000);
71 scene3 = SceneHelpers.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 random = new Random();
84 sog1 = SceneHelpers.CreateSceneObject(1, agent1);
85 scene.AddSceneObject(sog1);
86 sog2 = SceneHelpers.CreateSceneObject(1, agent1);
87 scene.AddSceneObject(sog2);
88 sog3 = SceneHelpers.CreateSceneObject(1, agent1);
89 scene.AddSceneObject(sog3);
90
91 region1 = scene.RegionInfo.RegionHandle;
92 region2 = scene2.RegionInfo.RegionHandle;
93 region3 = scene3.RegionInfo.RegionHandle;
94 }
95
96 [Test]
97 public void TestCloseAgent()
98 {
99 TestHelpers.InMethod();
100// log4net.Config.XmlConfigurator.Configure();
101
102 TestScene scene = SceneHelpers.SetupScene();
103 ScenePresence sp = SceneHelpers.AddScenePresence(scene, TestHelpers.ParseTail(0x1));
104
105 Assert.That(scene.AuthenticateHandler.GetAgentCircuitData(sp.UUID), Is.Not.Null);
106
107 scene.IncomingCloseAgent(sp.UUID);
108
109 Assert.That(scene.GetScenePresence(sp.UUID), Is.Null);
110 Assert.That(scene.AuthenticateHandler.GetAgentCircuitData(sp.UUID), Is.Null);
111 }
112
113 /// <summary>
114 /// Test that if a root agent logs into a region, a child agent is also established in the neighbouring region
115 /// </summary>
116 /// <remarks>
117 /// Please note that unlike the other tests here, this doesn't rely on structures
118 /// </remarks>
119 [Test]
120 public void TestChildAgentEstablished()
121 {
122 TestHelpers.InMethod();
123// log4net.Config.XmlConfigurator.Configure();
124
125 UUID agent1Id = UUID.Parse("00000000-0000-0000-0000-000000000001");
126
127 TestScene myScene1 = SceneHelpers.SetupScene("Neighbour y", UUID.Random(), 1000, 1000);
128// TestScene myScene2 = SceneHelpers.SetupScene("Neighbour y + 1", UUID.Random(), 1001, 1000);
129
130 IConfigSource configSource = new IniConfigSource();
131 configSource.AddConfig("Modules").Set("EntityTransferModule", "BasicEntityTransferModule");
132 EntityTransferModule etm = new EntityTransferModule();
133
134 SceneHelpers.SetupSceneModules(myScene1, configSource, etm);
135
136 SceneHelpers.AddScenePresence(myScene1, agent1Id);
137// ScenePresence childPresence = myScene2.GetScenePresence(agent1);
138
139 // TODO: Need to do a fair amount of work to allow synchronous establishment of child agents
140// Assert.That(childPresence, Is.Not.Null);
141// Assert.That(childPresence.IsChildAgent, Is.True);
142 }
143
144// /// <summary>
145// /// Test adding a root agent to a scene. Doesn't yet actually complete crossing the agent into the scene.
146// /// </summary>
147// [Test]
148// public void T010_TestAddRootAgent()
149// {
150// TestHelpers.InMethod();
151//
152// string firstName = "testfirstname";
153//
154// AgentCircuitData agent = new AgentCircuitData();
155// agent.AgentID = agent1;
156// agent.firstname = firstName;
157// agent.lastname = "testlastname";
158// agent.SessionID = UUID.Random();
159// agent.SecureSessionID = UUID.Random();
160// agent.circuitcode = 123;
161// agent.BaseFolder = UUID.Zero;
162// agent.InventoryFolder = UUID.Zero;
163// agent.startpos = Vector3.Zero;
164// agent.CapsPath = GetRandomCapsObjectPath();
165// agent.ChildrenCapSeeds = new Dictionary<ulong, string>();
166// agent.child = true;
167//
168// scene.PresenceService.LoginAgent(agent.AgentID.ToString(), agent.SessionID, agent.SecureSessionID);
169//
170// string reason;
171// scene.NewUserConnection(agent, (uint)TeleportFlags.ViaLogin, out reason);
172// testclient = new TestClient(agent, scene);
173// scene.AddNewClient(testclient);
174//
175// ScenePresence presence = scene.GetScenePresence(agent1);
176//
177// Assert.That(presence, Is.Not.Null, "presence is null");
178// Assert.That(presence.Firstname, Is.EqualTo(firstName), "First name not same");
179// acd1 = agent;
180// }
181//
182// /// <summary>
183// /// Test removing an uncrossed root agent from a scene.
184// /// </summary>
185// [Test]
186// public void T011_TestRemoveRootAgent()
187// {
188// TestHelpers.InMethod();
189//
190// scene.RemoveClient(agent1);
191//
192// ScenePresence presence = scene.GetScenePresence(agent1);
193//
194// Assert.That(presence, Is.Null, "presence is not null");
195// }
196
197 [Test]
198 public void T012_TestAddNeighbourRegion()
199 {
200 TestHelpers.InMethod();
201
202 string reason;
203
204 if (acd1 == null)
205 fixNullPresence();
206
207 scene.NewUserConnection(acd1, 0, out reason);
208 if (testclient == null)
209 testclient = new TestClient(acd1, scene);
210 scene.AddNewClient(testclient, PresenceType.User);
211
212 ScenePresence presence = scene.GetScenePresence(agent1);
213 presence.MakeRootAgent(new Vector3(90,90,90),false);
214
215 string cap = presence.ControllingClient.RequestClientInfo().CapsPath;
216
217 presence.AddNeighbourRegion(region2, cap);
218 presence.AddNeighbourRegion(region3, cap);
219
220 List<ulong> neighbours = presence.GetKnownRegionList();
221
222 Assert.That(neighbours.Count, Is.EqualTo(2));
223 }
224
225 [Test]
226 public void T013_TestRemoveNeighbourRegion()
227 {
228 TestHelpers.InMethod();
229
230 ScenePresence presence = scene.GetScenePresence(agent1);
231 presence.RemoveNeighbourRegion(region3);
232
233 List<ulong> neighbours = presence.GetKnownRegionList();
234 Assert.That(neighbours.Count,Is.EqualTo(1));
235 /*
236 presence.MakeChildAgent;
237 presence.MakeRootAgent;
238 CompleteAvatarMovement
239 */
240 }
241
242 // I'm commenting this test because it does not represent
243 // crossings. The Thread.Sleep's in here are not meaningful mocks,
244 // and they sometimes fail in panda.
245 // We need to talk in order to develop a test
246 // that really tests region crossings. There are 3 async components,
247 // but things are synchronous among them. So there should be
248 // 3 threads in here.
249 //[Test]
250 public void T021_TestCrossToNewRegion()
251 {
252 TestHelpers.InMethod();
253
254 scene.RegisterRegionWithGrid();
255 scene2.RegisterRegionWithGrid();
256
257 // Adding child agent to region 1001
258 string reason;
259 scene2.NewUserConnection(acd1,0, out reason);
260 scene2.AddNewClient(testclient, PresenceType.User);
261
262 ScenePresence presence = scene.GetScenePresence(agent1);
263 presence.MakeRootAgent(new Vector3(0,unchecked(Constants.RegionSize-1),0), true);
264
265 ScenePresence presence2 = scene2.GetScenePresence(agent1);
266
267 // Adding neighbour region caps info to presence2
268
269 string cap = presence.ControllingClient.RequestClientInfo().CapsPath;
270 presence2.AddNeighbourRegion(region1, cap);
271
272 Assert.That(presence.IsChildAgent, Is.False, "Did not start root in origin region.");
273 Assert.That(presence2.IsChildAgent, Is.True, "Is not a child on destination region.");
274
275 // Cross to x+1
276 presence.AbsolutePosition = new Vector3(Constants.RegionSize+1,3,100);
277 presence.Update();
278
279 EventWaitHandle wh = new EventWaitHandle (false, EventResetMode.AutoReset, "Crossing");
280
281 // Mimicking communication between client and server, by waiting OK from client
282 // sent by TestClient.CrossRegion call. Originally, this is network comm.
283 if (!wh.WaitOne(5000,false))
284 {
285 presence.Update();
286 if (!wh.WaitOne(8000,false))
287 throw new ArgumentException("1 - Timeout waiting for signal/variable.");
288 }
289
290 // This is a TestClient specific method that fires OnCompleteMovementToRegion event, which
291 // would normally be fired after receiving the reply packet from comm. done on the last line.
292 testclient.CompleteMovement();
293
294 // Crossings are asynchronous
295 int timer = 10;
296
297 // Make sure cross hasn't already finished
298 if (!presence.IsInTransit && !presence.IsChildAgent)
299 {
300 // If not and not in transit yet, give it some more time
301 Thread.Sleep(5000);
302 }
303
304 // Enough time, should at least be in transit by now.
305 while (presence.IsInTransit && timer > 0)
306 {
307 Thread.Sleep(1000);
308 timer-=1;
309 }
310
311 Assert.That(timer,Is.GreaterThan(0),"Timed out waiting to cross 2->1.");
312 Assert.That(presence.IsChildAgent, Is.True, "Did not complete region cross as expected.");
313 Assert.That(presence2.IsChildAgent, Is.False, "Did not receive root status after receiving agent.");
314
315 // Cross Back
316 presence2.AbsolutePosition = new Vector3(-10, 3, 100);
317 presence2.Update();
318
319 if (!wh.WaitOne(5000,false))
320 {
321 presence2.Update();
322 if (!wh.WaitOne(8000,false))
323 throw new ArgumentException("2 - Timeout waiting for signal/variable.");
324 }
325 testclient.CompleteMovement();
326
327 if (!presence2.IsInTransit && !presence2.IsChildAgent)
328 {
329 // If not and not in transit yet, give it some more time
330 Thread.Sleep(5000);
331 }
332
333 // Enough time, should at least be in transit by now.
334 while (presence2.IsInTransit && timer > 0)
335 {
336 Thread.Sleep(1000);
337 timer-=1;
338 }
339
340 Assert.That(timer,Is.GreaterThan(0),"Timed out waiting to cross 1->2.");
341 Assert.That(presence2.IsChildAgent, Is.True, "Did not return from region as expected.");
342 Assert.That(presence.IsChildAgent, Is.False, "Presence was not made root in old region again.");
343 }
344
345 public void fixNullPresence()
346 {
347 string firstName = "testfirstname";
348
349 AgentCircuitData agent = new AgentCircuitData();
350 agent.AgentID = agent1;
351 agent.firstname = firstName;
352 agent.lastname = "testlastname";
353 agent.SessionID = UUID.Zero;
354 agent.SecureSessionID = UUID.Zero;
355 agent.circuitcode = 123;
356 agent.BaseFolder = UUID.Zero;
357 agent.InventoryFolder = UUID.Zero;
358 agent.startpos = Vector3.Zero;
359 agent.CapsPath = GetRandomCapsObjectPath();
360 agent.Appearance = new AvatarAppearance();
361
362 acd1 = agent;
363 }
364
365 public static string GetRandomCapsObjectPath()
366 {
367 UUID caps = UUID.Random();
368 string capsPath = caps.ToString();
369 capsPath = capsPath.Remove(capsPath.Length - 4, 4);
370 return capsPath;
371 }
372 }
373} \ No newline at end of file