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