diff options
Diffstat (limited to 'OpenSim/Region/Framework/Scenes/Tests/ScenePresenceCrossingTests.cs')
-rw-r--r-- | OpenSim/Region/Framework/Scenes/Tests/ScenePresenceCrossingTests.cs | 157 |
1 files changed, 157 insertions, 0 deletions
diff --git a/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceCrossingTests.cs b/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceCrossingTests.cs new file mode 100644 index 0000000..81a2fcc --- /dev/null +++ b/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceCrossingTests.cs | |||
@@ -0,0 +1,157 @@ | |||
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 Nini.Config; | ||
32 | using NUnit.Framework; | ||
33 | using OpenMetaverse; | ||
34 | using OpenSim.Framework; | ||
35 | using OpenSim.Framework.Communications; | ||
36 | using OpenSim.Framework.Servers; | ||
37 | using OpenSim.Region.Framework.Interfaces; | ||
38 | using OpenSim.Region.CoreModules.Framework; | ||
39 | using OpenSim.Region.CoreModules.Framework.EntityTransfer; | ||
40 | using OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation; | ||
41 | using OpenSim.Tests.Common; | ||
42 | using OpenSim.Tests.Common.Mock; | ||
43 | |||
44 | namespace OpenSim.Region.Framework.Scenes.Tests | ||
45 | { | ||
46 | [TestFixture] | ||
47 | public class ScenePresenceCrossingTests : OpenSimTestCase | ||
48 | { | ||
49 | [TestFixtureSetUp] | ||
50 | public void FixtureInit() | ||
51 | { | ||
52 | // Don't allow tests to be bamboozled by asynchronous events. Execute everything on the same thread. | ||
53 | Util.FireAndForgetMethod = FireAndForgetMethod.RegressionTest; | ||
54 | } | ||
55 | |||
56 | [TestFixtureTearDown] | ||
57 | public void TearDown() | ||
58 | { | ||
59 | // We must set this back afterwards, otherwise later tests will fail since they're expecting multiple | ||
60 | // threads. Possibly, later tests should be rewritten so none of them require async stuff (which regression | ||
61 | // tests really shouldn't). | ||
62 | Util.FireAndForgetMethod = Util.DefaultFireAndForgetMethod; | ||
63 | } | ||
64 | |||
65 | [Test] | ||
66 | public void TestCrossOnSameSimulator() | ||
67 | { | ||
68 | TestHelpers.InMethod(); | ||
69 | // TestHelpers.EnableLogging(); | ||
70 | |||
71 | UUID userId = TestHelpers.ParseTail(0x1); | ||
72 | |||
73 | // TestEventQueueGetModule eqmA = new TestEventQueueGetModule(); | ||
74 | EntityTransferModule etmA = new EntityTransferModule(); | ||
75 | EntityTransferModule etmB = new EntityTransferModule(); | ||
76 | LocalSimulationConnectorModule lscm = new LocalSimulationConnectorModule(); | ||
77 | |||
78 | IConfigSource config = new IniConfigSource(); | ||
79 | IConfig modulesConfig = config.AddConfig("Modules"); | ||
80 | modulesConfig.Set("EntityTransferModule", etmA.Name); | ||
81 | modulesConfig.Set("SimulationServices", lscm.Name); | ||
82 | // IConfig entityTransferConfig = config.AddConfig("EntityTransfer"); | ||
83 | |||
84 | // In order to run a single threaded regression test we do not want the entity transfer module waiting | ||
85 | // for a callback from the destination scene before removing its avatar data. | ||
86 | // entityTransferConfig.Set("wait_for_callback", false); | ||
87 | |||
88 | SceneHelpers sh = new SceneHelpers(); | ||
89 | TestScene sceneA = sh.SetupScene("sceneA", TestHelpers.ParseTail(0x100), 1000, 1000); | ||
90 | TestScene sceneB = sh.SetupScene("sceneB", TestHelpers.ParseTail(0x200), 1000, 999); | ||
91 | |||
92 | SceneHelpers.SetupSceneModules(new Scene[] { sceneA, sceneB }, config, lscm); | ||
93 | SceneHelpers.SetupSceneModules(sceneA, config, new CapabilitiesModule(), etmA); | ||
94 | // SceneHelpers.SetupSceneModules(sceneA, config, new CapabilitiesModule(), etmA, eqmA); | ||
95 | SceneHelpers.SetupSceneModules(sceneB, config, new CapabilitiesModule(), etmB); | ||
96 | |||
97 | ScenePresence originalSp = SceneHelpers.AddScenePresence(sceneA, userId, sh.SceneManager); | ||
98 | originalSp.AbsolutePosition = new Vector3(128, 32, 10); | ||
99 | |||
100 | // originalSp.Flying = true; | ||
101 | |||
102 | // Console.WriteLine("First pos {0}", originalSp.AbsolutePosition); | ||
103 | |||
104 | // eqmA.ClearEvents(); | ||
105 | |||
106 | AgentUpdateArgs moveArgs = new AgentUpdateArgs(); | ||
107 | //moveArgs.BodyRotation = Quaternion.CreateFromEulers(Vector3.Zero); | ||
108 | moveArgs.BodyRotation = Quaternion.CreateFromEulers(new Vector3(0, 0, (float)-(Math.PI / 2))); | ||
109 | moveArgs.ControlFlags = (uint)AgentManager.ControlFlags.AGENT_CONTROL_AT_POS; | ||
110 | |||
111 | originalSp.HandleAgentUpdate(originalSp.ControllingClient, moveArgs); | ||
112 | |||
113 | sceneA.Update(1); | ||
114 | |||
115 | // Console.WriteLine("Second pos {0}", originalSp.AbsolutePosition); | ||
116 | |||
117 | // FIXME: This is a sufficient number of updates to for the presence to reach the northern border. | ||
118 | // But really we want to do this in a more robust way. | ||
119 | for (int i = 0; i < 100; i++) | ||
120 | { | ||
121 | sceneA.Update(1); | ||
122 | // Console.WriteLine("Pos {0}", originalSp.AbsolutePosition); | ||
123 | } | ||
124 | |||
125 | // Need to sort processing of EnableSimulator message on adding scene presences before we can test eqm | ||
126 | // messages | ||
127 | // Dictionary<UUID, List<TestEventQueueGetModule.Event>> eqmEvents = eqmA.Events; | ||
128 | // | ||
129 | // Assert.That(eqmEvents.Count, Is.EqualTo(1)); | ||
130 | // Assert.That(eqmEvents.ContainsKey(originalSp.UUID), Is.True); | ||
131 | // | ||
132 | // List<TestEventQueueGetModule.Event> spEqmEvents = eqmEvents[originalSp.UUID]; | ||
133 | // | ||
134 | // Assert.That(spEqmEvents.Count, Is.EqualTo(1)); | ||
135 | // Assert.That(spEqmEvents[0].Name, Is.EqualTo("CrossRegion")); | ||
136 | |||
137 | // sceneA should now only have a child agent | ||
138 | ScenePresence spAfterCrossSceneA = sceneA.GetScenePresence(originalSp.UUID); | ||
139 | Assert.That(spAfterCrossSceneA.IsChildAgent, Is.True); | ||
140 | |||
141 | ScenePresence spAfterCrossSceneB = sceneB.GetScenePresence(originalSp.UUID); | ||
142 | |||
143 | // Agent remains a child until the client triggers complete movement | ||
144 | Assert.That(spAfterCrossSceneB.IsChildAgent, Is.True); | ||
145 | |||
146 | TestClient sceneBTc = ((TestClient)spAfterCrossSceneB.ControllingClient); | ||
147 | |||
148 | int agentMovementCompleteReceived = 0; | ||
149 | sceneBTc.OnReceivedMoveAgentIntoRegion += (ri, pos, look) => agentMovementCompleteReceived++; | ||
150 | |||
151 | sceneBTc.CompleteMovement(); | ||
152 | |||
153 | Assert.That(agentMovementCompleteReceived, Is.EqualTo(1)); | ||
154 | Assert.That(spAfterCrossSceneB.IsChildAgent, Is.False); | ||
155 | } | ||
156 | } | ||
157 | } \ No newline at end of file | ||