From 8a949f0ee10a450de7b44f9d366e24847f69d23f Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Sat, 25 Oct 2014 00:32:46 +0100 Subject: Add regression tests for token buckets on their own --- .../ClientStack/Linden/UDP/Tests/ThrottleTests.cs | 50 +++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) (limited to 'OpenSim') diff --git a/OpenSim/Region/ClientStack/Linden/UDP/Tests/ThrottleTests.cs b/OpenSim/Region/ClientStack/Linden/UDP/Tests/ThrottleTests.cs index f7f69de..cd87928 100644 --- a/OpenSim/Region/ClientStack/Linden/UDP/Tests/ThrottleTests.cs +++ b/OpenSim/Region/ClientStack/Linden/UDP/Tests/ThrottleTests.cs @@ -55,6 +55,54 @@ namespace OpenSim.Region.ClientStack.LindenUDP.Tests } [Test] + public void TestSetRequestDripRate() + { + TokenBucket tb = new TokenBucket("tb", null, 5000, 0); + AssertRates(tb, 5000, 5000, 0); + + tb.RequestedDripRate = 4000; + AssertRates(tb, 4000, 4000, 0); + + tb.RequestedDripRate = 6000; + AssertRates(tb, 6000, 6000, 0); + } + + [Test] + public void TestSetRequestDripRateWithMax() + { + TokenBucket tb = new TokenBucket("tb", null, 5000, 10000); + AssertRates(tb, 5000, 5000, 10000); + + tb.RequestedDripRate = 4000; + AssertRates(tb, 4000, 4000, 10000); + + tb.RequestedDripRate = 6000; + AssertRates(tb, 6000, 6000, 10000); + + tb.RequestedDripRate = 12000; + AssertRates(tb, 10000, 10000, 10000); + } + + [Test] + public void TestSetRequestDripRateWithChildren() + { + TokenBucket tbParent = new TokenBucket("tbParent", null, 0, 0); + TokenBucket tbChild1 = new TokenBucket("tbChild1", tbParent, 3000, 0); + TokenBucket tbChild2 = new TokenBucket("tbChild2", tbParent, 5000, 0); + + AssertRates(tbParent, 8000, 8000, 0); + AssertRates(tbChild1, 3000, 3000, 0); + AssertRates(tbChild2, 5000, 5000, 0); + } + + private void AssertRates(TokenBucket tb, double dripRate, double totalDripRequest, double maxDripRate) + { + Assert.AreEqual((int)dripRate, tb.DripRate); + Assert.AreEqual((int)totalDripRequest, tb.TotalDripRequest); + Assert.AreEqual((int)maxDripRate, tb.MaxDripRate); + } + + [Test] public void TestClientThrottleSetNoLimit() { TestHelpers.InMethod(); @@ -179,7 +227,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP.Tests resendBytes / 2, landBytes / 2, windBytes / 2, cloudBytes / 2, taskBytes / 2, textureBytes / 2, assetBytes / 2, totalBytes, 0, 0); - // Now add another client + // Test: Now add another client ScenePresence sp2 = ClientStackHelpers.AddChildClient( scene, udpServer, TestHelpers.ParseTail(0x10), TestHelpers.ParseTail(0x20), 123457); -- cgit v1.1