fix(core): Adds Hashed & Hierarchical Timer Wheel (#655)
- Removes TimerPriority - Removes TimerThread - Adds a [Hashed & Hierarchical Timer Wheel](http://www.cs.columbia.edu/~nahum/w6998/papers/ton97-timing-wheels.pdf)
This commit is contained in:
parent
b99d520019
commit
fb915992dd
138 changed files with 468 additions and 802 deletions
|
|
@ -18,12 +18,15 @@ namespace Server.Tests
|
|||
// Configure the world
|
||||
World.Configure();
|
||||
|
||||
Timer.Initialize(0);
|
||||
|
||||
// Load the world
|
||||
World.Load();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Timer.Initialize(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ using Xunit;
|
|||
|
||||
namespace Server.Tests.Network
|
||||
{
|
||||
[Collection("Sequential Tests")]
|
||||
public class MobilePacketTests : IClassFixture<ServerFixture>
|
||||
{
|
||||
[Fact]
|
||||
|
|
@ -328,11 +329,7 @@ namespace Server.Tests.Network
|
|||
var result = ns.SendPipe.Reader.TryRead();
|
||||
AssertThat.Equal(result.Buffer[0].AsSpan(0), expected);
|
||||
}
|
||||
}
|
||||
|
||||
[Collection("Sequential Tests")]
|
||||
public class SequentialMobilePacketTests : IClassFixture<ServerFixture>
|
||||
{
|
||||
[Fact]
|
||||
public void TestMobileHits()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ using Xunit;
|
|||
|
||||
namespace Server.Tests.Network
|
||||
{
|
||||
[Collection("Sequential Tests")]
|
||||
public class PlayerPacketTests : IClassFixture<ServerFixture>
|
||||
{
|
||||
[Theory]
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ using Xunit;
|
|||
|
||||
namespace Server.Tests.Network
|
||||
{
|
||||
[Collection("Sequential Tests")]
|
||||
public class VendorBuyPacketTests : IClassFixture<ServerFixture>
|
||||
{
|
||||
[Theory]
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ using Xunit;
|
|||
|
||||
namespace Server.Tests.Network
|
||||
{
|
||||
[Collection("Sequential Tests")]
|
||||
public class VendorSellPacketTests : IClassFixture<ServerFixture>
|
||||
{
|
||||
[Fact]
|
||||
|
|
|
|||
78
Projects/Server.Tests/Tests/Timer/TimerTests.cs
Normal file
78
Projects/Server.Tests/Tests/Timer/TimerTests.cs
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
using System;
|
||||
using Xunit;
|
||||
|
||||
namespace Server.Tests
|
||||
{
|
||||
[Collection("Sequential Tests")]
|
||||
public class TimerTests : IClassFixture<ServerFixture>
|
||||
{
|
||||
[Theory]
|
||||
[InlineData(0L, 8L)]
|
||||
[InlineData(80L, 80L)]
|
||||
[InlineData(65L, 72L)]
|
||||
[InlineData(32767L, 32768L)]
|
||||
[InlineData(32768L, 32768L)]
|
||||
[InlineData(32833L, 32840L)]
|
||||
[InlineData(134217729L, 134217736L)]
|
||||
public void TestVariousTimes(long ticks, long expectedTicks)
|
||||
{
|
||||
var timerTicks = new TimerTicks();
|
||||
void action()
|
||||
{
|
||||
Assert.Equal(expectedTicks, timerTicks.Ticks);
|
||||
timerTicks.ExecutedCount++;
|
||||
}
|
||||
|
||||
Timer.Initialize(timerTicks.Ticks);
|
||||
|
||||
var timer = Timer.DelayCall(TimeSpan.FromMilliseconds(ticks), action);
|
||||
timer.Start();
|
||||
|
||||
var tickCount = expectedTicks / 8;
|
||||
|
||||
for (int i = 1; i <= tickCount; i++)
|
||||
{
|
||||
timerTicks.Ticks = i * 8;
|
||||
|
||||
Timer.Slice(timerTicks.Ticks);
|
||||
}
|
||||
|
||||
Assert.Equal(1, timerTicks.ExecutedCount);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(1000L, 1000L, 30000L, 30000L, 2)]
|
||||
public void TestIntervals(long delay, long expectedDelayTicks, long interval, long expectedIntervalTicks, int count)
|
||||
{
|
||||
var timerTicks = new TimerTicks();
|
||||
void action()
|
||||
{
|
||||
timerTicks.ExpectedTicks += timerTicks.ExecutedCount++ == 0 ? expectedDelayTicks : expectedIntervalTicks;
|
||||
Assert.Equal(timerTicks.ExpectedTicks, timerTicks.Ticks);
|
||||
}
|
||||
|
||||
Timer.Initialize(timerTicks.Ticks);
|
||||
|
||||
var timer = Timer.DelayCall(TimeSpan.FromMilliseconds(delay), TimeSpan.FromMilliseconds(interval), count, action);
|
||||
timer.Start();
|
||||
|
||||
var tickCount = (expectedDelayTicks + (expectedIntervalTicks * count - 1)) / 8;
|
||||
|
||||
for (int i = 1; i <= tickCount; i++)
|
||||
{
|
||||
timerTicks.Ticks = i * 8;
|
||||
|
||||
Timer.Slice(timerTicks.Ticks);
|
||||
}
|
||||
|
||||
Assert.Equal(count, timerTicks.ExecutedCount);
|
||||
}
|
||||
|
||||
private class TimerTicks
|
||||
{
|
||||
public long ExpectedTicks;
|
||||
public long Ticks;
|
||||
public int ExecutedCount;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue