Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various test changes #2930

Merged
merged 9 commits into from
Jun 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Robust.Client/GameStates/ClientGameStateManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ public void ApplyGameState()
var hasPendingInput = pendingInputEnumerator.MoveNext();
var hasPendingMessage = pendingMessagesEnumerator.MoveNext();

var ping = _network.ServerChannel!.Ping / 1000f + PredictLagBias; // seconds.
var ping = (_network.ServerChannel?.Ping ?? 0) / 1000f + PredictLagBias; // seconds.
var targetTick = _timing.CurTick.Value + _processor.TargetBufferSize +
(int) Math.Ceiling(_timing.TickRate * ping) + PredictTickBias;

Expand Down
1 change: 0 additions & 1 deletion Robust.Client/Player/PlayerManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ private void UpdateAttachedEntity(EntityUid? entity)
{
return;
}

if (entity == null)
{
LocalPlayer.DetachEntity();
Expand Down
18 changes: 15 additions & 3 deletions Robust.Shared/Prototypes/PrototypeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,12 @@ public interface IPrototypeManager
/// </summary>
void ResolveResults();

/// <summary>
/// Reload the changes from LoadString
/// </summary>
/// <param name="prototypes">Changes from load string</param>
void ReloadPrototypes(Dictionary<Type, HashSet<string>> prototypes);

/// <summary>
/// Registers a specific prototype name to be ignored.
/// </summary>
Expand Down Expand Up @@ -315,7 +321,7 @@ protected void ReloadPrototypes(IEnumerable<ResourcePath> filePaths)
#endif
}

internal void ReloadPrototypes(Dictionary<Type, HashSet<string>> prototypes)
public void ReloadPrototypes(Dictionary<Type, HashSet<string>> prototypes)
{
#if !FULL_RELEASE
var prototypeTypeOrder = prototypes.Keys.ToList();
Expand Down Expand Up @@ -609,7 +615,10 @@ public void RemoveString(string prototypes)
foreach (var node in root.Cast<YamlMappingNode>())
{
var typeString = node.GetNode("type").AsString();
var type = _prototypeTypes[typeString];
if (!_prototypeTypes.TryGetValue(typeString, out var type))
{
continue;
}

var id = node.GetNode("id").AsString();

Expand All @@ -618,7 +627,10 @@ public void RemoveString(string prototypes)
tree.RemoveId(id);
}

_prototypes[type].Remove(id);
if (_prototypes.TryGetValue(type, out var prototypeIds))
{
prototypeIds.Remove(id);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using JetBrains.Annotations;
using Robust.Shared.IoC;
using Robust.Shared.Log;
using Robust.Shared.Network;
using Robust.Shared.Reflection;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.Serialization.Manager.Definition;
Expand All @@ -34,7 +35,7 @@ public sealed partial class SerializationManager : ISerializationManager
private bool _initialized;

// Using CWT<,> here in case we ever want assembly unloading.
private static readonly ConditionalWeakTable<Type, DataDefinition> DataDefinitions = new();
private readonly ConditionalWeakTable<Type, DataDefinition> DataDefinitions = new();
private readonly HashSet<Type> _copyByRefRegistrations = new();

public IDependencyCollection DependencyCollection { get; private set; } = default!;
Expand Down
6 changes: 4 additions & 2 deletions Robust.UnitTesting/RobustIntegrationTest.NetManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Net;
using System.Threading.Channels;
using System.Threading.Tasks;
using Robust.Shared.Asynchronous;
using Robust.Shared.IoC;
using Robust.Shared.Network;
using Robust.Shared.Timing;
Expand All @@ -17,6 +18,7 @@ public partial class RobustIntegrationTest
internal sealed class IntegrationNetManager : IClientNetManager, IServerNetManager
{
[Dependency] private readonly IGameTiming _gameTiming = default!;
[Dependency] private readonly ITaskManager _taskManager = default!;
public bool IsServer { get; private set; }
public bool IsClient => !IsServer;
public bool IsRunning { get; private set; }
Expand Down Expand Up @@ -106,7 +108,7 @@ public void ProcessPackets()
{
DebugTools.Assert(IsServer);

async void DoConnect()
async Task DoConnect()
{
var writer = connect.ChannelWriter;

Expand Down Expand Up @@ -139,7 +141,7 @@ async void DoConnect()
Connected?.Invoke(this, new NetChannelArgs(channel));
}

DoConnect();
_taskManager.BlockWaitOnTask(DoConnect());

break;
}
Expand Down
25 changes: 20 additions & 5 deletions Robust.UnitTesting/RobustIntegrationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,17 @@ private async Task WaitIdleImplAsync(bool throwOnUnhandled, CancellationToken ca
{
while (_isAlive && _currentTicksId != _ackTicksId)
{
var msg = await _fromInstanceReader.ReadAsync(cancellationToken);
object msg = default!;
try
{
msg = await _fromInstanceReader.ReadAsync(cancellationToken);
}
catch(OperationCanceledException ex)
{
_unhandledException = ex;
_isAlive = false;
break;
}
switch (msg)
{
case ShutDownMessage shutDownMessage:
Expand Down Expand Up @@ -475,6 +485,7 @@ public void Stop()
// Won't get ack'd directly but the shutdown is convincing enough.
_currentTicksId += 1;
_toInstanceWriter.TryWrite(new StopMessage());
_toInstanceWriter.TryComplete();
}

/// <summary>
Expand Down Expand Up @@ -526,7 +537,7 @@ public void Dispose()

public sealed class ServerIntegrationInstance : IntegrationInstance
{
internal ServerIntegrationInstance(ServerIntegrationOptions? options) : base(options)
public ServerIntegrationInstance(ServerIntegrationOptions? options) : base(options)
{
ServerOptions = options;
DependencyCollection = new DependencyCollection();
Expand Down Expand Up @@ -654,7 +665,7 @@ private BaseServer Init()

public sealed class ClientIntegrationInstance : IntegrationInstance
{
internal ClientIntegrationInstance(ClientIntegrationOptions? options) : base(options)
public ClientIntegrationInstance(ClientIntegrationOptions? options) : base(options)
{
ClientOptions = options;
DependencyCollection = new DependencyCollection();
Expand Down Expand Up @@ -839,8 +850,12 @@ public void Run()

while (Running)
{
_channelReader.WaitToReadAsync().AsTask().Wait();

var readerNotDone = _channelReader.WaitToReadAsync().AsTask().GetAwaiter().GetResult();
if (!readerNotDone)
{
Running = false;
return;
}
SingleThreadRunUntilEmpty();
}
}
Expand Down