Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public void OnEnabled(ICheatEngineClient client)
"The Lua module lifecycle has already been enabled for this activation.");
}

_lease = _lua.RegisterModule(_module);
_lease = _lua.RegisterModule(_module, client.Stopping);
}

public void OnDisabling(ICheatEngineClient client)
Expand Down
5 changes: 4 additions & 1 deletion tests/CheatEngine.Client.Benchmarks/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

return BenchmarkEntryPoint.Run(args);

namespace CheatEngine.Client.Benchmarks
{
internal static class BenchmarkEntryPoint
{
public static int Run(string[] args)
Expand All @@ -17,7 +19,7 @@ public static int Run(string[] args)
.AddExporter(JsonExporter.Full);

Summary[] summaries = BenchmarkSwitcher
.FromAssembly(typeof(Program).Assembly)
.FromAssembly(typeof(BenchmarkEntryPoint).Assembly)
.Run(args, config)
.ToArray();

Expand Down Expand Up @@ -124,3 +126,4 @@ public static bool HasError(this IEnumerable<Summary> summaries)
summary.Reports.Any(static report => !report.Success));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,19 @@ public void LuaModuleLifecycleRegistersAndReleasesItsModuleExactlyOnce()
Assert.Equal(1, lease.DisposeCount);
}

[Fact]
public void LuaModuleLifecycleForwardsTheClientStoppingTokenToRegistration()
{
RecordingLuaClient lua = new();
LuaModuleLifecycle<FirstLuaModule> lifecycle = new(lua, new FirstLuaModule());
using CancellationTokenSource stopping = new();
TestClient client = new() { Stopping = stopping.Token };

lifecycle.OnEnabled(client);

Assert.Equal(client.Stopping, lua.RegistrationCancellationToken);
}

private readonly record struct CustomValue(int Value);

private sealed class FirstCustomCodec : IMemoryCodec<CustomValue>
Expand Down Expand Up @@ -346,13 +359,20 @@ internal ILuaModule? RegisteredModule
private set;
}

internal CancellationToken RegistrationCancellationToken
{
get;
private set;
}

public bool TryRegisterModule(
ILuaModule luaModule,
[NotNullWhen(true)] out ILuaModuleLease? lease,
out CheatEngineFailure failure,
CancellationToken cancellationToken = default)
{
ArgumentNullException.ThrowIfNull(luaModule);
RegistrationCancellationToken = cancellationToken;
RegisteredModule = luaModule;
Lease = new RecordingLease();
lease = Lease;
Expand Down Expand Up @@ -417,7 +437,11 @@ private sealed class TestClient : ICheatEngineClient
{
public long Epoch => 1;

public CancellationToken Stopping => CancellationToken.None;
public CancellationToken Stopping
{
get;
init;
} = CancellationToken.None;

public ICheatEngineRuntime Runtime => null!;

Expand Down