Skip to content
Draft
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
20 changes: 10 additions & 10 deletions .github/workflows/build-github.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,31 @@ jobs:

steps:
# 1. Checkout source
- name: Checkout repository
uses: actions/checkout@v4
- name: 1. Checkout repository
uses: actions/checkout@v5
with:
fetch-depth: 0 # ensure tags/commits info is available when we expand logic later

# 2. Setup .NET SDK
- name: Setup .NET
- name: 2. Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '10.0.x' # Change to your target version

# 3. Restore dependencies
- name: Restore dependencies
- name: 3. Restore dependencies
run: dotnet restore

# 4. Build solution
- name: Build
- name: 4. Build
run: dotnet build --configuration Release --no-restore

# 5. Run tests
- name: Test
- name: 5. Test
run: dotnet test --configuration Release --no-build --verbosity normal

# 6. Determin SemVersion package version
- name: Determine version
- name: 6. Determine version
shell: pwsh
run: |
$branch = "${{ github.ref_name }}"
Expand Down Expand Up @@ -73,7 +73,7 @@ jobs:
if ($prerelease) { Write-Host "Version suffix=$prerelease" }

# 7. Pack NuGet
- name: Pack NuGet
- name: 7. Pack NuGet
run: dotnet pack --configuration Release --no-build --output ./artifacts
#- name: Pack NuGet
# shell: pwsh
Expand All @@ -89,7 +89,7 @@ jobs:


# 8. Create ZIP of artifacts
- name: Create ZIP archive
- name: 8. Create ZIP archive
run: |
mkdir ./zip
powershell Compress-Archive -Path ./artifacts/* -DestinationPath ./zip/artifacts.zip
Expand All @@ -100,7 +100,7 @@ jobs:
# Compress-Archive -Path ./artifacts/* -DestinationPath ./zip/artifacts.zip

# 9. Upload ZIP as workflow artifact
- name: Upload ZIP
- name: 9. Upload ZIP
uses: actions/upload-artifact@v4
with:
name: nuget-package-zip
Expand Down
7 changes: 5 additions & 2 deletions src/Lite.EventIpc.Tests/BaseTestClass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// See the LICENSE file in the project root for more information.

using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Console;

namespace Lite.EventIpc.Tests;

Expand All @@ -23,11 +24,13 @@ protected ILogger<T> CreateConsoleLogger<T>(LogLevel minimumLevel = LogLevel.Deb
var factory = LoggerFactory.Create(config =>
{
//// config.AddConsole();
config.AddConsole(options =>
config.AddSimpleConsole(options =>
{
options.TimestampFormat = "[HH:mm:ss.fff] ";
options.TimestampFormat = "HH:mm:ss.fff ";
options.UseUtcTimestamp = false;
options.IncludeScopes = true;
options.SingleLine = true;
options.ColorBehavior = LoggerColorBehavior.Enabled;
});
config.SetMinimumLevel(minimumLevel);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Threading.Tasks;
using Lite.EventIpc.IpcReceiptTransport;
using Lite.EventIpc.Tests.Models;
using Microsoft.Extensions.Logging;

namespace Lite.EventIpc.Tests.IpcReceiptedTransporters;

Expand All @@ -19,14 +20,20 @@ public class MemoryMappedTests : BaseTestClass
private const string SignalRequestName = "ipc-req-signal";
private const string SignalResponseName = "ipc-resp-signal";

[TestInitialize]
public void CleanupTestInitialize()
{
_logger = CreateConsoleLogger<EventAggregator>(LogLevel.Trace);
}

[TestMethod]
public async Task Request_Response_Via_MemoryMappedAsync()
{
const string PayloadRequest = "hello";
const string PayloadResponse = " mmf";
const string MsgRequest = "hello";
const string MsgResponse = " mmf";

var client = new EventAggregator();
var server = new EventAggregator();
var client = new EventAggregator(_logger);
var server = new EventAggregator(_logger);

var serverTransport = new MemoryMappedEnvelopeTransport(
requestMapName: MapRequestName,
Expand All @@ -43,26 +50,36 @@ public async Task Request_Response_Via_MemoryMappedAsync()
await server.UseIpcEnvelopeTransportAsync(serverTransport);
await client.UseIpcEnvelopeTransportAsync(clientTransport);

bool wasReceived = false;
bool msgReceived = false;
////server.SubscribeRequest<Ping, Pong>(async (req) =>
////{
//// _logger?.LogInformation("Test Subscriber received Ping, returning Pong..");
//// msgReceived = true;
//// await Task.Yield();
//// return new Pong(req.Message + MsgResponse);
////});

// TODO: We need to trigger a cancellation after sending this back, and set
// that the transmission was a success
// TODO-2: Gotta return without using "Task.FromResult" that's lame!
server.SubscribeRequest<Ping, Pong>(req =>
{
Console.WriteLine("Subscriber received Ping, returning Pong..");
wasReceived = true;
return Task.FromResult(new Pong(req.Message + PayloadResponse));
_logger?.LogInformation("Test Subscriber received Ping, returning Pong..");
msgReceived = true;
return Task.FromResult(new Pong(req.Message + MsgResponse));
});

Console.WriteLine("Sending Ping...");
_logger?.LogInformation("Test Sending Ping...");
var resp = await client.RequestAsync<Ping, Pong>(
new Ping(PayloadRequest),
timeout: TimeSpan.FromMilliseconds(DefaultTimeout200),
TestContext.CancellationToken);
new Ping(MsgRequest),
timeout: TimeSpan.FromMilliseconds(3_000));

Console.WriteLine("Receiver recognized: " + wasReceived);
Console.WriteLine("Response is null: " + resp is null);
_logger?.LogInformation("Test Msg Received: {WasRcv}", msgReceived);
_logger?.LogInformation("Test Response is null: {IsNull}", resp is null ? "NULL" : "HasValue");
Task.Delay(DefaultTimeout).Wait();

Assert.IsTrue(wasReceived);
Assert.AreEqual(PayloadRequest + PayloadResponse, resp.Message);
Assert.IsTrue(msgReceived);
Assert.AreEqual(MsgRequest + MsgResponse, resp.Message);
}
}

Expand Down
1 change: 1 addition & 0 deletions src/Lite.EventIpc.slnx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<BuildType Name="Release" />
</Configurations>
<Folder Name="/Solution Items/">
<File Path="../.github/workflows/build-github.yml" />
<File Path="../LICENSE.md" />
<File Path="../readme.md" />
<File Path=".editorconfig" />
Expand Down
14 changes: 12 additions & 2 deletions src/Lite.EventIpc/EventAggregator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,23 +176,31 @@ public async Task<TResponse> RequestAsync<TRequest, TResponse>(TRequest request,

using (effectiveCt.Register(() =>
{
// TODO (2025-11-30) Need to determine if we 'canceled' with success or failed with Timeout
if (_pendingRequests.TryRemove(correlationId, out var pr))
{
// TODO (2025-11-28): Fix receipted timeout exception handling. It always throws and fails to cast to TResponse
//// pr.Payload.SetResult(pr);
pr.Payload.TrySetException(new TimeoutException($"Request timed out after {timeout ?? _defaultTimeout}."));
pr.Payload.SetResult(pr);
////pr.Payload.TrySetException(new TimeoutException($"Request timed out after {timeout ?? _defaultTimeout}."));

if (_logger is not null && _logger.IsEnabled(LogLevel.Warning))
_logger.LogWarning("Request {CorrelationId} timed out after {Timeout}", correlationId, effectiveTimeout);
}
else
{
if (_logger is not null && _logger.IsEnabled(LogLevel.Warning))
_logger.LogWarning("Request {CorrelationId} not found and timed out after {Timeout}", correlationId, effectiveTimeout);
}
}))
{
// For receipted IPC events only
if (envelope is not null)
await _ipcEnvelopeTransport!.SendAsync(envelope, effectiveCt).ConfigureAwait(false);

// TODO: (2025-11-28): Fix receipted timeout exception handling. It always fails to cast 'PendingRequest' to TResponse
// TODO: Wait for receiving
var obj = await pending.Payload.Task.ConfigureAwait(false);
////object? obj = await pending.Payload.Task; ////.Task.ConfigureAwait(false);
if (_logger is not null && _logger.IsEnabled(LogLevel.Information))
_logger.LogInformation("Received response for {CorrelationId}", correlationId);

Expand Down Expand Up @@ -363,6 +371,7 @@ private async Task OnTransportMessageAsync(EventEnvelope envelope)
return;
}

// Handle Envelope Response
if (envelope.IsResponse)
{
if (_pendingRequests.TryRemove(envelope.CorrelationId, out var pr))
Expand Down Expand Up @@ -396,6 +405,7 @@ private async Task OnTransportMessageAsync(EventEnvelope envelope)
return;
}

// Handle Envelope Response
if (envelope.IsRequest)
{
var handler = GetFirstRequestHandler(eventType);
Expand Down
Loading