From 8477aab8e02b2f829d4946e051d36f11ae2e4839 Mon Sep 17 00:00:00 2001
From: Justin Clarke Casey
Date: Thu, 6 Nov 2008 18:27:56 +0000
Subject: * refactor: factor out test packet send method in client stack unit
tests
---
.../LindenUDP/Tests/BasicCircuitTests.cs | 50 ++++++++++++++++++----
.../ClientStack/LindenUDP/Tests/TestLLUDPServer.cs | 26 ++++++++++-
2 files changed, 66 insertions(+), 10 deletions(-)
(limited to 'OpenSim/Region/ClientStack/LindenUDP')
diff --git a/OpenSim/Region/ClientStack/LindenUDP/Tests/BasicCircuitTests.cs b/OpenSim/Region/ClientStack/LindenUDP/Tests/BasicCircuitTests.cs
index d55f423..6210d0c 100644
--- a/OpenSim/Region/ClientStack/LindenUDP/Tests/BasicCircuitTests.cs
+++ b/OpenSim/Region/ClientStack/LindenUDP/Tests/BasicCircuitTests.cs
@@ -113,6 +113,23 @@ namespace OpenSim.Region.ClientStack.LindenUDP.Tests
}
///
+ /// Build an object name packet for test purposes
+ ///
+ ///
+ ///
+ protected ObjectNamePacket BuildTestObjectNamePacket(uint objectLocalId, string objectName)
+ {
+ ObjectNamePacket onp = new ObjectNamePacket();
+ ObjectNamePacket.ObjectDataBlock odb = new ObjectNamePacket.ObjectDataBlock();
+ odb.LocalID = objectLocalId;
+ odb.Name = Utils.StringToBytes(objectName);
+ onp.ObjectData = new ObjectNamePacket.ObjectDataBlock[] { odb };
+ onp.Header.Zerocoded = false;
+
+ return onp;
+ }
+
+ ///
/// Test adding a client to the stack
///
[Test]
@@ -209,19 +226,36 @@ namespace OpenSim.Region.ClientStack.LindenUDP.Tests
// Check that sending a valid packet to same circuit still succeeds
Assert.That(scene.ObjectNameCallsReceived, Is.EqualTo(0));
-
- ObjectNamePacket onp = new ObjectNamePacket();
- ObjectNamePacket.ObjectDataBlock odb = new ObjectNamePacket.ObjectDataBlock();
- odb.LocalID = 1;
- odb.Name = Utils.StringToBytes("helloooo");
- onp.ObjectData = new ObjectNamePacket.ObjectDataBlock[] { odb };
- onp.Header.Zerocoded = false;
- testLLUDPServer.LoadReceive(onp, testEp);
+ testLLUDPServer.LoadReceive(BuildTestObjectNamePacket(1, "helloooo"), testEp);
testLLUDPServer.ReceiveData(null);
Assert.That(testLLPacketServer.GetTotalPacketsReceived(), Is.EqualTo(1));
Assert.That(testLLPacketServer.GetPacketsReceivedFor(PacketType.ObjectName), Is.EqualTo(1));
}
+
+ ///
+ /// Test that the stack continues to work even if some client has caused a
+ /// SocketException on Socket.BeginReceive()
+ ///
+ [Test]
+ public void TestExceptionOnBeginReceive()
+ {
+ /*
+ MockScene scene = new MockScene();
+
+ uint circuitCodeA = 130000;
+ EndPoint epA = new IPEndPoint(IPAddress.Loopback, 1300);
+ uint circuitCodeB = 130001;
+ EndPoint epB = new IPEndPoint(IPAddress.Loopback, 1301);
+
+ TestLLUDPServer testLLUDPServer;
+ TestLLPacketServer testLLPacketServer;
+ AgentCircuitManager acm;
+ SetupStack(scene, out testLLUDPServer, out testLLPacketServer, out acm);
+ AddClient(circuitCodeA, epA, testLLUDPServer, acm);
+ AddClient(circuitCodeB, epB, testLLUDPServer, acm);
+ */
+ }
}
}
diff --git a/OpenSim/Region/ClientStack/LindenUDP/Tests/TestLLUDPServer.cs b/OpenSim/Region/ClientStack/LindenUDP/Tests/TestLLUDPServer.cs
index dd7afd3..002b493 100644
--- a/OpenSim/Region/ClientStack/LindenUDP/Tests/TestLLUDPServer.cs
+++ b/OpenSim/Region/ClientStack/LindenUDP/Tests/TestLLUDPServer.cs
@@ -48,7 +48,12 @@ namespace OpenSim.Region.ClientStack.LindenUDP.Tests
protected override void BeginReceive()
{
- // Do nothing
+ if (m_chunksToLoad.Count > 0 && m_chunksToLoad.Peek().BeginReceiveException)
+ {
+ ChunkSenderTuple tuple = m_chunksToLoad.Dequeue();
+ reusedEpSender = tuple.Sender;
+ throw new SocketException();
+ }
}
protected override bool EndReceive(out int numBytes, IAsyncResult result, ref EndPoint epSender)
@@ -72,6 +77,17 @@ namespace OpenSim.Region.ClientStack.LindenUDP.Tests
}
///
+ /// Signal that this chunk should throw an exception on Socket.BeginReceive()
+ ///
+ ///
+ public void LoadReceiveWithBeginException(EndPoint epSender)
+ {
+ ChunkSenderTuple tuple = new ChunkSenderTuple(epSender);
+ tuple.BeginReceiveException = true;
+ m_chunksToLoad.Enqueue(tuple);
+ }
+
+ ///
/// Load some data to be received by the LLUDPServer on the next receive call
///
///
@@ -118,14 +134,20 @@ namespace OpenSim.Region.ClientStack.LindenUDP.Tests
/// Record the data and sender tuple
///
public class ChunkSenderTuple
- {
+ {
public byte[] Data;
public EndPoint Sender;
+ public bool BeginReceiveException;
public ChunkSenderTuple(byte[] data, EndPoint sender)
{
Data = data;
Sender = sender;
}
+
+ public ChunkSenderTuple(EndPoint sender)
+ {
+ Sender = sender;
+ }
}
}
\ No newline at end of file
--
cgit v1.1