Add basic regression test ThrottleTests.TestClientThrottleSetNoLimit

mb-throttle-test
Justin Clark-Casey (justincc) 2014-10-08 20:52:17 +01:00
parent 52370ac94d
commit 746defa094
2 changed files with 114 additions and 0 deletions

View File

@ -415,6 +415,14 @@ namespace OpenSim.Region.ClientStack.LindenUDP
int texture = (int)(BitConverter.ToSingle(adjData, pos) * 0.125f); pos += 4; int texture = (int)(BitConverter.ToSingle(adjData, pos) * 0.125f); pos += 4;
int asset = (int)(BitConverter.ToSingle(adjData, pos) * 0.125f); int asset = (int)(BitConverter.ToSingle(adjData, pos) * 0.125f);
if (ThrottleDebugLevel > 0)
{
long total = resend + land + wind + cloud + task + texture + asset;
m_log.DebugFormat(
"[LLUDPCLIENT]: {0} is setting throttles in {1} to Resend={2}, Land={3}, Wind={4}, Cloud={5}, Task={6}, Texture={7}, Asset={8}, TOTAL = {9}",
AgentID, m_udpServer.Scene.Name, resend, land, wind, cloud, task, texture, asset, total);
}
// Make sure none of the throttles are set below our packet MTU, // Make sure none of the throttles are set below our packet MTU,
// otherwise a throttle could become permanently clogged // otherwise a throttle could become permanently clogged
resend = Math.Max(resend, LLUDPServer.MTU); resend = Math.Max(resend, LLUDPServer.MTU);

View File

@ -0,0 +1,106 @@
/*
* Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the OpenSimulator Project nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
using System;
using NUnit.Framework;
using OpenMetaverse.Packets;
using OpenSim.Framework;
using OpenSim.Region.Framework.Scenes;
using OpenSim.Tests.Common;
namespace OpenSim.Region.ClientStack.LindenUDP.Tests
{
[TestFixture]
public class ThrottleTests : OpenSimTestCase
{
[TestFixtureSetUp]
public void FixtureInit()
{
// Don't allow tests to be bamboozled by asynchronous events. Execute everything on the same thread.
Util.FireAndForgetMethod = FireAndForgetMethod.RegressionTest;
}
[TestFixtureTearDown]
public void TearDown()
{
// We must set this back afterwards, otherwise later tests will fail since they're expecting multiple
// threads. Possibly, later tests should be rewritten so none of them require async stuff (which regression
// tests really shouldn't).
Util.FireAndForgetMethod = Util.DefaultFireAndForgetMethod;
}
[Test]
public void TestClientThrottleSetNoLimit()
{
TestHelpers.InMethod();
TestHelpers.EnableLogging();
Scene scene = new SceneHelpers().SetupScene();
TestLLUDPServer udpServer = ClientStackHelpers.AddUdpServer(scene);
ScenePresence sp
= ClientStackHelpers.AddChildClient(
scene, udpServer, TestHelpers.ParseTail(0x1), TestHelpers.ParseTail(0x2), 123456);
LLUDPClient udpClient = ((LLClientView)sp.ControllingClient).UDPClient;
// udpClient.ThrottleDebugLevel = 1;
byte[] throttles = new byte[28];
float resendBits = 10000;
float landBits = 20000;
float windBits = 30000;
float cloudBits = 40000;
float taskBits = 50000;
float textureBits = 60000;
float assetBits = 70000;
Array.Copy(BitConverter.GetBytes(resendBits), 0, throttles, 0, 4);
Array.Copy(BitConverter.GetBytes(landBits), 0, throttles, 4, 4);
Array.Copy(BitConverter.GetBytes(windBits), 0, throttles, 8, 4);
Array.Copy(BitConverter.GetBytes(cloudBits), 0, throttles, 12, 4);
Array.Copy(BitConverter.GetBytes(taskBits), 0, throttles, 16, 4);
Array.Copy(BitConverter.GetBytes(textureBits), 0, throttles, 20, 4);
Array.Copy(BitConverter.GetBytes(assetBits), 0, throttles, 24, 4);
// Console.WriteLine(BitConverter.ToString(throttles));
udpClient.SetThrottles(throttles);
ClientInfo ci = udpClient.GetClientInfo();
// We expect this to be lower because of the minimum bound set by MTU
float totalBits = LLUDPServer.MTU * 8 + landBits + windBits + cloudBits + taskBits + textureBits + assetBits;
Assert.AreEqual(LLUDPServer.MTU, ci.resendThrottle);
Assert.AreEqual(landBits / 8, ci.landThrottle);
Assert.AreEqual(windBits / 8, ci.windThrottle);
Assert.AreEqual(cloudBits / 8, ci.cloudThrottle);
Assert.AreEqual(taskBits / 8, ci.taskThrottle);
Assert.AreEqual(textureBits / 8, ci.textureThrottle);
Assert.AreEqual(assetBits / 8, ci.assetThrottle);
Assert.AreEqual(totalBits / 8, ci.totalThrottle);
}
}
}