* refactor: factor out test packet send method in client stack unit tests

0.6.0-stable
Justin Clarke Casey 2008-11-06 18:27:56 +00:00
parent 46492f3c11
commit 8477aab8e0
2 changed files with 66 additions and 10 deletions

View File

@ -112,6 +112,23 @@ namespace OpenSim.Region.ClientStack.LindenUDP.Tests
testLLUDPServer.ReceiveData(null); testLLUDPServer.ReceiveData(null);
} }
/// <summary>
/// Build an object name packet for test purposes
/// </summary>
/// <param name="objectLocalId"></param>
/// <param name="objectName"></param>
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;
}
/// <summary> /// <summary>
/// Test adding a client to the stack /// Test adding a client to the stack
/// </summary> /// </summary>
@ -210,18 +227,35 @@ namespace OpenSim.Region.ClientStack.LindenUDP.Tests
// Check that sending a valid packet to same circuit still succeeds // Check that sending a valid packet to same circuit still succeeds
Assert.That(scene.ObjectNameCallsReceived, Is.EqualTo(0)); Assert.That(scene.ObjectNameCallsReceived, Is.EqualTo(0));
ObjectNamePacket onp = new ObjectNamePacket(); testLLUDPServer.LoadReceive(BuildTestObjectNamePacket(1, "helloooo"), testEp);
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.ReceiveData(null); testLLUDPServer.ReceiveData(null);
Assert.That(testLLPacketServer.GetTotalPacketsReceived(), Is.EqualTo(1)); Assert.That(testLLPacketServer.GetTotalPacketsReceived(), Is.EqualTo(1));
Assert.That(testLLPacketServer.GetPacketsReceivedFor(PacketType.ObjectName), Is.EqualTo(1)); Assert.That(testLLPacketServer.GetPacketsReceivedFor(PacketType.ObjectName), Is.EqualTo(1));
} }
/// <summary>
/// Test that the stack continues to work even if some client has caused a
/// SocketException on Socket.BeginReceive()
/// </summary>
[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);
*/
}
} }
} }

View File

@ -48,7 +48,12 @@ namespace OpenSim.Region.ClientStack.LindenUDP.Tests
protected override void BeginReceive() 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) protected override bool EndReceive(out int numBytes, IAsyncResult result, ref EndPoint epSender)
@ -71,6 +76,17 @@ namespace OpenSim.Region.ClientStack.LindenUDP.Tests
// Don't do anything just yet // Don't do anything just yet
} }
/// <summary>
/// Signal that this chunk should throw an exception on Socket.BeginReceive()
/// </summary>
/// <param name="epSender"></param>
public void LoadReceiveWithBeginException(EndPoint epSender)
{
ChunkSenderTuple tuple = new ChunkSenderTuple(epSender);
tuple.BeginReceiveException = true;
m_chunksToLoad.Enqueue(tuple);
}
/// <summary> /// <summary>
/// Load some data to be received by the LLUDPServer on the next receive call /// Load some data to be received by the LLUDPServer on the next receive call
/// </summary> /// </summary>
@ -121,11 +137,17 @@ namespace OpenSim.Region.ClientStack.LindenUDP.Tests
{ {
public byte[] Data; public byte[] Data;
public EndPoint Sender; public EndPoint Sender;
public bool BeginReceiveException;
public ChunkSenderTuple(byte[] data, EndPoint sender) public ChunkSenderTuple(byte[] data, EndPoint sender)
{ {
Data = data; Data = data;
Sender = sender; Sender = sender;
} }
public ChunkSenderTuple(EndPoint sender)
{
Sender = sender;
}
} }
} }