fix: Fixes hanging tests (#1535)

This commit is contained in:
Kamron Batman 2023-10-09 00:22:59 -07:00 committed by GitHub
parent d0d81d0d5f
commit 629a5008c3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 4 deletions

View file

@ -30,6 +30,8 @@ internal class ServerFixture : IDisposable
// Load the world // Load the world
World.Load(); World.Load();
World.ExitSerializationThreads();
} }
public void Dispose() public void Dispose()

View file

@ -398,6 +398,8 @@ public static class Core
World.WaitForWriteCompletion(); World.WaitForWriteCompletion();
World.ExitSerializationThreads();
if (!_crashed) if (!_crashed)
{ {
EventSink.InvokeShutdown(); EventSink.InvokeShutdown();
@ -587,7 +589,7 @@ public static class Core
} }
finally finally
{ {
World.SleepSerializationThreads(); World.ExitSerializationThreads();
} }
} }

View file

@ -383,11 +383,11 @@ public static class World
} }
} }
internal static void SleepSerializationThreads() public static void ExitSerializationThreads()
{ {
for (var i = 0; i < _threadWorkers.Length; i++) for (var i = 0; i < _threadWorkers.Length; i++)
{ {
_threadWorkers[i].Sleep(); _threadWorkers[i].Exit();
} }
} }
@ -524,6 +524,7 @@ public static class World
private readonly AutoResetEvent _startEvent; // Main thread tells the thread to start working private readonly AutoResetEvent _startEvent; // Main thread tells the thread to start working
private readonly AutoResetEvent _stopEvent; // Main thread waits for the worker finish draining private readonly AutoResetEvent _stopEvent; // Main thread waits for the worker finish draining
private bool _pause; private bool _pause;
private bool _exit;
private readonly ConcurrentQueue<IGenericSerializable> _entities; private readonly ConcurrentQueue<IGenericSerializable> _entities;
public SerializationThreadWorker() public SerializationThreadWorker()
@ -546,6 +547,13 @@ public static class World
_stopEvent.WaitOne(); _stopEvent.WaitOne();
} }
public void Exit()
{
_exit = true;
Wake();
Sleep();
}
public void Push(IGenericSerializable entity) public void Push(IGenericSerializable entity)
{ {
_entities.Enqueue(entity); _entities.Enqueue(entity);
@ -576,7 +584,7 @@ public static class World
worker._stopEvent.Set(); // Allow the main thread to continue now that we are finished worker._stopEvent.Set(); // Allow the main thread to continue now that we are finished
worker._pause = false; worker._pause = false;
if (Core.Closing) if (Core.Closing || worker._exit)
{ {
return; return;
} }

View file

@ -37,6 +37,8 @@ namespace Server.Tests
// Load the world // Load the world
World.Load(); World.Load();
World.ExitSerializationThreads();
} }
public void Dispose() public void Dispose()