diff options
author | Justin Clark-Casey (justincc) | 2014-10-08 20:17:51 +0100 |
---|---|---|
committer | Justin Clark-Casey (justincc) | 2014-11-25 23:18:40 +0000 |
commit | 52370ac94de4f449645eb0471fab4cc515fccbe2 (patch) | |
tree | 1b920cad4f0416420a8fec9f804b1272bf92166e /OpenSim/Region | |
parent | Fix recent regression in "debug lludp throttles get" command that stopped it ... (diff) | |
download | opensim-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/Region')
-rw-r--r-- | OpenSim/Region/ClientStack/Linden/UDP/Tests/BasicCircuitTests.cs | 71 | ||||
-rw-r--r-- | OpenSim/Region/ClientStack/Linden/UDP/Tests/TestLLUDPServer.cs | 170 |
2 files changed, 12 insertions, 229 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/Region/ClientStack/Linden/UDP/Tests/TestLLUDPServer.cs b/OpenSim/Region/ClientStack/Linden/UDP/Tests/TestLLUDPServer.cs deleted file mode 100644 index 27b9e5b..0000000 --- a/OpenSim/Region/ClientStack/Linden/UDP/Tests/TestLLUDPServer.cs +++ /dev/null | |||
@@ -1,170 +0,0 @@ | |||
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.Net; | ||
31 | using System.Net.Sockets; | ||
32 | using Nini.Config; | ||
33 | using OpenMetaverse.Packets; | ||
34 | using OpenSim.Framework; | ||
35 | |||
36 | namespace OpenSim.Region.ClientStack.LindenUDP.Tests | ||
37 | { | ||
38 | /// <summary> | ||
39 | /// This class enables regression testing of the LLUDPServer by allowing us to intercept outgoing data. | ||
40 | /// </summary> | ||
41 | public class TestLLUDPServer : LLUDPServer | ||
42 | { | ||
43 | public List<Packet> PacketsSent { get; private set; } | ||
44 | |||
45 | public TestLLUDPServer(IPAddress listenIP, ref uint port, int proxyPortOffsetParm, bool allow_alternate_port, IConfigSource configSource, AgentCircuitManager circuitManager) | ||
46 | : base(listenIP, ref port, proxyPortOffsetParm, allow_alternate_port, configSource, circuitManager) | ||
47 | { | ||
48 | PacketsSent = new List<Packet>(); | ||
49 | } | ||
50 | |||
51 | public override void SendAckImmediate(IPEndPoint remoteEndpoint, PacketAckPacket ack) | ||
52 | { | ||
53 | PacketsSent.Add(ack); | ||
54 | } | ||
55 | |||
56 | public override void SendPacket( | ||
57 | LLUDPClient udpClient, Packet packet, ThrottleOutPacketType category, bool allowSplitting, UnackedPacketMethod method) | ||
58 | { | ||
59 | PacketsSent.Add(packet); | ||
60 | } | ||
61 | |||
62 | public void ClientOutgoingPacketHandler(IClientAPI client, bool resendUnacked, bool sendAcks, bool sendPing) | ||
63 | { | ||
64 | m_resendUnacked = resendUnacked; | ||
65 | m_sendAcks = sendAcks; | ||
66 | m_sendPing = sendPing; | ||
67 | |||
68 | ClientOutgoingPacketHandler(client); | ||
69 | } | ||
70 | |||
71 | //// /// <summary> | ||
72 | //// /// The chunks of data to pass to the LLUDPServer when it calls EndReceive | ||
73 | //// /// </summary> | ||
74 | //// protected Queue<ChunkSenderTuple> m_chunksToLoad = new Queue<ChunkSenderTuple>(); | ||
75 | // | ||
76 | //// protected override void BeginReceive() | ||
77 | //// { | ||
78 | //// if (m_chunksToLoad.Count > 0 && m_chunksToLoad.Peek().BeginReceiveException) | ||
79 | //// { | ||
80 | //// ChunkSenderTuple tuple = m_chunksToLoad.Dequeue(); | ||
81 | //// reusedEpSender = tuple.Sender; | ||
82 | //// throw new SocketException(); | ||
83 | //// } | ||
84 | //// } | ||
85 | // | ||
86 | //// protected override bool EndReceive(out int numBytes, IAsyncResult result, ref EndPoint epSender) | ||
87 | //// { | ||
88 | //// numBytes = 0; | ||
89 | //// | ||
90 | //// //m_log.Debug("Queue size " + m_chunksToLoad.Count); | ||
91 | //// | ||
92 | //// if (m_chunksToLoad.Count <= 0) | ||
93 | //// return false; | ||
94 | //// | ||
95 | //// ChunkSenderTuple tuple = m_chunksToLoad.Dequeue(); | ||
96 | //// RecvBuffer = tuple.Data; | ||
97 | //// numBytes = tuple.Data.Length; | ||
98 | //// epSender = tuple.Sender; | ||
99 | //// | ||
100 | //// return true; | ||
101 | //// } | ||
102 | // | ||
103 | //// public override void SendPacketTo(byte[] buffer, int size, SocketFlags flags, uint circuitcode) | ||
104 | //// { | ||
105 | //// // Don't do anything just yet | ||
106 | //// } | ||
107 | // | ||
108 | // /// <summary> | ||
109 | // /// Signal that this chunk should throw an exception on Socket.BeginReceive() | ||
110 | // /// </summary> | ||
111 | // /// <param name="epSender"></param> | ||
112 | // public void LoadReceiveWithBeginException(EndPoint epSender) | ||
113 | // { | ||
114 | // ChunkSenderTuple tuple = new ChunkSenderTuple(epSender); | ||
115 | // tuple.BeginReceiveException = true; | ||
116 | // m_chunksToLoad.Enqueue(tuple); | ||
117 | // } | ||
118 | // | ||
119 | // /// <summary> | ||
120 | // /// Load some data to be received by the LLUDPServer on the next receive call | ||
121 | // /// </summary> | ||
122 | // /// <param name="data"></param> | ||
123 | // /// <param name="epSender"></param> | ||
124 | // public void LoadReceive(byte[] data, EndPoint epSender) | ||
125 | // { | ||
126 | // m_chunksToLoad.Enqueue(new ChunkSenderTuple(data, epSender)); | ||
127 | // } | ||
128 | // | ||
129 | // /// <summary> | ||
130 | // /// Load a packet to be received by the LLUDPServer on the next receive call | ||
131 | // /// </summary> | ||
132 | // /// <param name="packet"></param> | ||
133 | // public void LoadReceive(Packet packet, EndPoint epSender) | ||
134 | // { | ||
135 | // LoadReceive(packet.ToBytes(), epSender); | ||
136 | // } | ||
137 | // | ||
138 | // /// <summary> | ||
139 | // /// Calls the protected asynchronous result method. This fires out all data chunks currently queued for send | ||
140 | // /// </summary> | ||
141 | // /// <param name="result"></param> | ||
142 | // public void ReceiveData(IAsyncResult result) | ||
143 | // { | ||
144 | // // Doesn't work the same way anymore | ||
145 | //// while (m_chunksToLoad.Count > 0) | ||
146 | //// OnReceivedData(result); | ||
147 | // } | ||
148 | } | ||
149 | |||
150 | /// <summary> | ||
151 | /// Record the data and sender tuple | ||
152 | /// </summary> | ||
153 | public class ChunkSenderTuple | ||
154 | { | ||
155 | public byte[] Data; | ||
156 | public EndPoint Sender; | ||
157 | public bool BeginReceiveException; | ||
158 | |||
159 | public ChunkSenderTuple(byte[] data, EndPoint sender) | ||
160 | { | ||
161 | Data = data; | ||
162 | Sender = sender; | ||
163 | } | ||
164 | |||
165 | public ChunkSenderTuple(EndPoint sender) | ||
166 | { | ||
167 | Sender = sender; | ||
168 | } | ||
169 | } | ||
170 | } | ||