aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
diff options
context:
space:
mode:
authorJustin Clark-Casey (justincc)2014-10-08 20:17:51 +0100
committerJustin Clark-Casey (justincc)2014-11-25 23:18:40 +0000
commit52370ac94de4f449645eb0471fab4cc515fccbe2 (patch)
tree1b920cad4f0416420a8fec9f804b1272bf92166e /OpenSim
parentFix recent regression in "debug lludp throttles get" command that stopped it ... (diff)
downloadopensim-SC_OLD-52370ac94de4f449645eb0471fab4cc515fccbe2.zip
opensim-SC_OLD-52370ac94de4f449645eb0471fab4cc515fccbe2.tar.gz
opensim-SC_OLD-52370ac94de4f449645eb0471fab4cc515fccbe2.tar.bz2
opensim-SC_OLD-52370ac94de4f449645eb0471fab4cc515fccbe2.tar.xz
refactor: Move test clientstack setup code out of BasicCircuitTests into OpenSim.Tests.Common.ClientStackHelpers
Diffstat (limited to 'OpenSim')
-rw-r--r--OpenSim/Region/ClientStack/Linden/UDP/Tests/BasicCircuitTests.cs71
-rw-r--r--OpenSim/Tests/Common/Helpers/ClientStackHelpers.cs95
-rw-r--r--OpenSim/Tests/Common/Mock/TestLLUDPServer.cs (renamed from OpenSim/Region/ClientStack/Linden/UDP/Tests/TestLLUDPServer.cs)3
3 files changed, 109 insertions, 60 deletions
diff --git a/OpenSim/Region/ClientStack/Linden/UDP/Tests/BasicCircuitTests.cs b/OpenSim/Region/ClientStack/Linden/UDP/Tests/BasicCircuitTests.cs
index e9aeffe..ef5e861 100644
--- a/OpenSim/Region/ClientStack/Linden/UDP/Tests/BasicCircuitTests.cs
+++ b/OpenSim/Region/ClientStack/Linden/UDP/Tests/BasicCircuitTests.cs
@@ -47,7 +47,6 @@ namespace OpenSim.Region.ClientStack.LindenUDP.Tests
47 public class BasicCircuitTests : OpenSimTestCase 47 public class BasicCircuitTests : OpenSimTestCase
48 { 48 {
49 private Scene m_scene; 49 private Scene m_scene;
50 private TestLLUDPServer m_udpServer;
51 50
52 [TestFixtureSetUp] 51 [TestFixtureSetUp]
53 public void FixtureInit() 52 public void FixtureInit()
@@ -90,55 +89,6 @@ namespace OpenSim.Region.ClientStack.LindenUDP.Tests
90 return onp; 89 return onp;
91 } 90 }
92 91
93 private void AddUdpServer()
94 {
95 AddUdpServer(new IniConfigSource());
96 }
97
98 private void AddUdpServer(IniConfigSource configSource)
99 {
100 uint port = 0;
101 AgentCircuitManager acm = m_scene.AuthenticateHandler;
102
103 m_udpServer = new TestLLUDPServer(IPAddress.Any, ref port, 0, false, configSource, acm);
104 m_udpServer.AddScene(m_scene);
105 }
106
107 /// <summary>
108 /// Used by tests that aren't testing this stage.
109 /// </summary>
110 private ScenePresence AddClient()
111 {
112 UUID myAgentUuid = TestHelpers.ParseTail(0x1);
113 UUID mySessionUuid = TestHelpers.ParseTail(0x2);
114 uint myCircuitCode = 123456;
115 IPEndPoint testEp = new IPEndPoint(IPAddress.Loopback, 999);
116
117 UseCircuitCodePacket uccp = new UseCircuitCodePacket();
118
119 UseCircuitCodePacket.CircuitCodeBlock uccpCcBlock
120 = new UseCircuitCodePacket.CircuitCodeBlock();
121 uccpCcBlock.Code = myCircuitCode;
122 uccpCcBlock.ID = myAgentUuid;
123 uccpCcBlock.SessionID = mySessionUuid;
124 uccp.CircuitCode = uccpCcBlock;
125
126 byte[] uccpBytes = uccp.ToBytes();
127 UDPPacketBuffer upb = new UDPPacketBuffer(testEp, uccpBytes.Length);
128 upb.DataLength = uccpBytes.Length; // God knows why this isn't set by the constructor.
129 Buffer.BlockCopy(uccpBytes, 0, upb.Data, 0, uccpBytes.Length);
130
131 AgentCircuitData acd = new AgentCircuitData();
132 acd.AgentID = myAgentUuid;
133 acd.SessionID = mySessionUuid;
134
135 m_scene.AuthenticateHandler.AddNewCircuit(myCircuitCode, acd);
136
137 m_udpServer.PacketReceived(upb);
138
139 return m_scene.GetScenePresence(myAgentUuid);
140 }
141
142 /// <summary> 92 /// <summary>
143 /// Test adding a client to the stack 93 /// Test adding a client to the stack
144 /// </summary> 94 /// </summary>
@@ -148,7 +98,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP.Tests
148 TestHelpers.InMethod(); 98 TestHelpers.InMethod();
149// TestHelpers.EnableLogging(); 99// TestHelpers.EnableLogging();
150 100
151 AddUdpServer(); 101 TestLLUDPServer udpServer = ClientStackHelpers.AddUdpServer(m_scene);
152 102
153 UUID myAgentUuid = TestHelpers.ParseTail(0x1); 103 UUID myAgentUuid = TestHelpers.ParseTail(0x1);
154 UUID mySessionUuid = TestHelpers.ParseTail(0x2); 104 UUID mySessionUuid = TestHelpers.ParseTail(0x2);
@@ -169,7 +119,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP.Tests
169 upb.DataLength = uccpBytes.Length; // God knows why this isn't set by the constructor. 119 upb.DataLength = uccpBytes.Length; // God knows why this isn't set by the constructor.
170 Buffer.BlockCopy(uccpBytes, 0, upb.Data, 0, uccpBytes.Length); 120 Buffer.BlockCopy(uccpBytes, 0, upb.Data, 0, uccpBytes.Length);
171 121
172 m_udpServer.PacketReceived(upb); 122 udpServer.PacketReceived(upb);
173 123
174 // Presence shouldn't exist since the circuit manager doesn't know about this circuit for authentication yet 124 // Presence shouldn't exist since the circuit manager doesn't know about this circuit for authentication yet
175 Assert.That(m_scene.GetScenePresence(myAgentUuid), Is.Null); 125 Assert.That(m_scene.GetScenePresence(myAgentUuid), Is.Null);
@@ -180,15 +130,15 @@ namespace OpenSim.Region.ClientStack.LindenUDP.Tests
180 130
181 m_scene.AuthenticateHandler.AddNewCircuit(myCircuitCode, acd); 131 m_scene.AuthenticateHandler.AddNewCircuit(myCircuitCode, acd);
182 132
183 m_udpServer.PacketReceived(upb); 133 udpServer.PacketReceived(upb);
184 134
185 // Should succeed now 135 // Should succeed now
186 ScenePresence sp = m_scene.GetScenePresence(myAgentUuid); 136 ScenePresence sp = m_scene.GetScenePresence(myAgentUuid);
187 Assert.That(sp.UUID, Is.EqualTo(myAgentUuid)); 137 Assert.That(sp.UUID, Is.EqualTo(myAgentUuid));
188 138
189 Assert.That(m_udpServer.PacketsSent.Count, Is.EqualTo(1)); 139 Assert.That(udpServer.PacketsSent.Count, Is.EqualTo(1));
190 140
191 Packet packet = m_udpServer.PacketsSent[0]; 141 Packet packet = udpServer.PacketsSent[0];
192 Assert.That(packet, Is.InstanceOf(typeof(PacketAckPacket))); 142 Assert.That(packet, Is.InstanceOf(typeof(PacketAckPacket)));
193 143
194 PacketAckPacket ackPacket = packet as PacketAckPacket; 144 PacketAckPacket ackPacket = packet as PacketAckPacket;
@@ -200,15 +150,18 @@ namespace OpenSim.Region.ClientStack.LindenUDP.Tests
200 public void TestLogoutClientDueToAck() 150 public void TestLogoutClientDueToAck()
201 { 151 {
202 TestHelpers.InMethod(); 152 TestHelpers.InMethod();
203 TestHelpers.EnableLogging(); 153// TestHelpers.EnableLogging();
204 154
205 IniConfigSource ics = new IniConfigSource(); 155 IniConfigSource ics = new IniConfigSource();
206 IConfig config = ics.AddConfig("ClientStack.LindenUDP"); 156 IConfig config = ics.AddConfig("ClientStack.LindenUDP");
207 config.Set("AckTimeout", -1); 157 config.Set("AckTimeout", -1);
208 AddUdpServer(ics); 158 TestLLUDPServer udpServer = ClientStackHelpers.AddUdpServer(m_scene, ics);
159
160 ScenePresence sp
161 = ClientStackHelpers.AddChildClient(
162 m_scene, udpServer, TestHelpers.ParseTail(0x1), TestHelpers.ParseTail(0x2), 123456);
209 163
210 ScenePresence sp = AddClient(); 164 udpServer.ClientOutgoingPacketHandler(sp.ControllingClient, true, false, false);
211 m_udpServer.ClientOutgoingPacketHandler(sp.ControllingClient, true, false, false);
212 165
213 ScenePresence spAfterAckTimeout = m_scene.GetScenePresence(sp.UUID); 166 ScenePresence spAfterAckTimeout = m_scene.GetScenePresence(sp.UUID);
214 Assert.That(spAfterAckTimeout, Is.Null); 167 Assert.That(spAfterAckTimeout, Is.Null);
diff --git a/OpenSim/Tests/Common/Helpers/ClientStackHelpers.cs b/OpenSim/Tests/Common/Helpers/ClientStackHelpers.cs
new file mode 100644
index 0000000..33cd8a2
--- /dev/null
+++ b/OpenSim/Tests/Common/Helpers/ClientStackHelpers.cs
@@ -0,0 +1,95 @@
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.Net;
30using Nini.Config;
31using OpenMetaverse;
32using OpenMetaverse.Packets;
33using OpenSim.Framework;
34using OpenSim.Region.ClientStack.LindenUDP;
35using OpenSim.Region.Framework.Scenes;
36
37namespace OpenSim.Tests.Common
38{
39 /// <summary>
40 /// This class adds full UDP client classes and associated scene presence to scene.
41 /// </summary>
42 /// <remarks>
43 /// This is used for testing client stack code. For testing other code, use SceneHelper methods instead since
44 /// they operate without the burden of setting up UDP structures which should be unnecessary for testing scene
45 /// code.
46 /// </remarks>
47 public static class ClientStackHelpers
48 {
49 public static ScenePresence AddChildClient(
50 Scene scene, LLUDPServer udpServer, UUID agentId, UUID sessionId, uint circuitCode)
51 {
52 IPEndPoint testEp = new IPEndPoint(IPAddress.Loopback, 999);
53
54 UseCircuitCodePacket uccp = new UseCircuitCodePacket();
55
56 UseCircuitCodePacket.CircuitCodeBlock uccpCcBlock
57 = new UseCircuitCodePacket.CircuitCodeBlock();
58 uccpCcBlock.Code = circuitCode;
59 uccpCcBlock.ID = agentId;
60 uccpCcBlock.SessionID = sessionId;
61 uccp.CircuitCode = uccpCcBlock;
62
63 byte[] uccpBytes = uccp.ToBytes();
64 UDPPacketBuffer upb = new UDPPacketBuffer(testEp, uccpBytes.Length);
65 upb.DataLength = uccpBytes.Length; // God knows why this isn't set by the constructor.
66 Buffer.BlockCopy(uccpBytes, 0, upb.Data, 0, uccpBytes.Length);
67
68 AgentCircuitData acd = new AgentCircuitData();
69 acd.AgentID = agentId;
70 acd.SessionID = sessionId;
71
72 scene.AuthenticateHandler.AddNewCircuit(circuitCode, acd);
73
74 udpServer.PacketReceived(upb);
75
76 return scene.GetScenePresence(agentId);
77 }
78
79 public static TestLLUDPServer AddUdpServer(Scene scene)
80 {
81 return AddUdpServer(scene, new IniConfigSource());
82 }
83
84 public static TestLLUDPServer AddUdpServer(Scene scene, IniConfigSource configSource)
85 {
86 uint port = 0;
87 AgentCircuitManager acm = scene.AuthenticateHandler;
88
89 TestLLUDPServer udpServer = new TestLLUDPServer(IPAddress.Any, ref port, 0, false, configSource, acm);
90 udpServer.AddScene(scene);
91
92 return udpServer;
93 }
94 }
95} \ No newline at end of file
diff --git a/OpenSim/Region/ClientStack/Linden/UDP/Tests/TestLLUDPServer.cs b/OpenSim/Tests/Common/Mock/TestLLUDPServer.cs
index 27b9e5b..26887c9 100644
--- a/OpenSim/Region/ClientStack/Linden/UDP/Tests/TestLLUDPServer.cs
+++ b/OpenSim/Tests/Common/Mock/TestLLUDPServer.cs
@@ -32,8 +32,9 @@ using System.Net.Sockets;
32using Nini.Config; 32using Nini.Config;
33using OpenMetaverse.Packets; 33using OpenMetaverse.Packets;
34using OpenSim.Framework; 34using OpenSim.Framework;
35using OpenSim.Region.ClientStack.LindenUDP;
35 36
36namespace OpenSim.Region.ClientStack.LindenUDP.Tests 37namespace OpenSim.Tests.Common
37{ 38{
38 /// <summary> 39 /// <summary>
39 /// This class enables regression testing of the LLUDPServer by allowing us to intercept outgoing data. 40 /// This class enables regression testing of the LLUDPServer by allowing us to intercept outgoing data.