Enhance school management and protocol handling by introducing a new worker failure mechanism, ensuring proper cleanup of schools when a worker thread encounters an error. Update the map snapshot protocol to allow larger school data sizes, improving the handling of extensive map layouts. Revise documentation to reflect changes in save intervals and introduce a minimum save interval for better performance. Update tests to validate the new functionalities and ensure robustness in handling large data scenarios.
This commit is contained in:
@@ -158,6 +158,52 @@ public class ProtocolCodecTests
|
||||
Assert.Equal(["Директор"], read.Nodes[1].Positions);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MapSnapshotSize_IsExactlyWhatTheWriterProduces()
|
||||
{
|
||||
var message = new ServerMapSnapshotMessage(7, [
|
||||
new MapSnapshotNode(0, "yard", "", "Двор", [], []),
|
||||
new MapSnapshotNode(2, "floor-1", "main", "Этаж 1", [], []),
|
||||
new MapSnapshotNode(3, "office", "floor-1", "Кабинет директора", ["Стол", "Стул"], ["Директор"]),
|
||||
]);
|
||||
|
||||
var size = ProtocolCodec.MapSnapshotSize(message);
|
||||
var buffer = new byte[size];
|
||||
|
||||
Assert.Equal(size, ProtocolCodec.WriteMapSnapshot(buffer, message));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MapSnapshot_OfALargeSchoolSurvivesTheEightKilobyteLimit()
|
||||
{
|
||||
// A player who keeps clicking "Add room" in the create editor gets past 8 KiB somewhere
|
||||
// around sixty furnished rooms. Sizing the buffer from the message is what keeps that
|
||||
// school openable instead of killing its worker thread on the first snapshot.
|
||||
var nodes = new List<MapSnapshotNode> { new(0, "yard", "", "Двор", [], []) };
|
||||
for (var i = 1; i <= 200; i++)
|
||||
{
|
||||
nodes.Add(new MapSnapshotNode(
|
||||
3,
|
||||
$"principals-office-{i}",
|
||||
"floor-1",
|
||||
"Кабинет директора",
|
||||
["Кресло директора", "Стол", "Стул"],
|
||||
["Директор"]));
|
||||
}
|
||||
|
||||
var message = new ServerMapSnapshotMessage(1, nodes);
|
||||
var buffer = new byte[ProtocolCodec.MapSnapshotSize(message)];
|
||||
|
||||
Assert.True(buffer.Length > ProtocolConstants.MaxMessageSize);
|
||||
|
||||
var length = ProtocolCodec.WriteMapSnapshot(buffer, message);
|
||||
var read = ProtocolCodec.ReadMapSnapshot(buffer.AsSpan(0, length));
|
||||
|
||||
Assert.Equal(nodes.Count, read.Nodes.Count);
|
||||
Assert.Equal("principals-office-200", read.Nodes[^1].Id);
|
||||
Assert.Equal(["Кресло директора", "Стол", "Стул"], read.Nodes[^1].Items);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Numbers_AreLittleEndian()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user