Skip to content

Commit

Permalink
simplifications after review
Browse files Browse the repository at this point in the history
- decommission WaitForStop
  • Loading branch information
eduard-dumitru committed Nov 28, 2024
1 parent ce5c4a2 commit 59fe065
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ IEnumerable<Task> EnumeratePings()
}
});

await Task.WhenAll(ipcServers.Select(ipcServer => ipcServer.WaitForStop()));
await Task.Delay(Timeout.InfiniteTimeSpan);

IpcServer CreateAndStartIpcServer(ServerTransport transport)
{
Expand Down
3 changes: 0 additions & 3 deletions src/UiPath.CoreIpc/Config/IpcServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ public sealed class IpcServer : IpcBase, IAsyncDisposable

private readonly object _lock = new();
private readonly TaskCompletionSource<object?> _listening = new();
private readonly TaskCompletionSource<object?> _stopped = new();
private readonly CancellationTokenSource _ctsActiveConnections = new();

private bool _disposeStarted;
Expand Down Expand Up @@ -70,7 +69,6 @@ public Task WaitForStart()
Start();
return _accepter.StartedAccepting;
}
public Task WaitForStop() => _stopped.Task;

internal ILogger? CreateLogger(string category) => ServiceProvider.MaybeCreateLogger(category);

Expand All @@ -82,7 +80,6 @@ private void OnNewConnection(Stream network)
private void OnNewConnectionError(Exception ex)
{
Trace.TraceError($"Failed to accept new connection. Ex: {ex}");
_stopped.TrySetException(ex);
}

internal RouterConfig CreateRouterConfig(IpcServer server) => RouterConfig.From(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ namespace UiPath.Ipc
"_accepter"})]
public void Start() { }
public System.Threading.Tasks.Task WaitForStart() { }
public System.Threading.Tasks.Task WaitForStop() { }
}
public class Message
{
Expand Down
58 changes: 39 additions & 19 deletions src/UiPath.Ipc.Tests/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,50 @@
using UiPath.Ipc;
using UiPath.Ipc.Tests;

if (args is not [var base64])
using (ConsoleCancellation(out var ct))
{
Console.Error.WriteLine($"Usage: dotnet {Path.GetFileName(Assembly.GetEntryAssembly()!.Location)} <BASE64(AssemblyQualifiedName(ComputingTests sealed subtype))>");
return 1;
return await Entry(ct);
}
var externalServerParams = JsonConvert.DeserializeObject<ComputingTests.ExternalServerParams>(Encoding.UTF8.GetString(Convert.FromBase64String(base64)));
await using var asyncDisposable = externalServerParams.CreateListenerConfig(out var serverTransport);

await using var serviceProvider = new ServiceCollection()
.AddLogging(builder => builder.AddConsole())
.AddSingleton<IComputingService, ComputingService>()
.BuildServiceProvider();

await using var ipcServer = new IpcServer()
async Task<int> Entry(CancellationToken ct)
{
ServiceProvider = serviceProvider,
Scheduler = new ConcurrentExclusiveSchedulerPair().ExclusiveScheduler,
Endpoints = new()
if (args is not [var base64])
{
Console.Error.WriteLine($"Usage: dotnet {Path.GetFileName(Assembly.GetEntryAssembly()!.Location)} <BASE64(AssemblyQualifiedName(ComputingTests sealed subtype))>");
return 1;
}
var externalServerParams = JsonConvert.DeserializeObject<ComputingTests.ExternalServerParams>(Encoding.UTF8.GetString(Convert.FromBase64String(base64)));
await using var asyncDisposable = externalServerParams.CreateListenerConfig(out var serverTransport);

await using var serviceProvider = new ServiceCollection()
.AddLogging(builder => builder.AddConsole())
.AddSingleton<IComputingService, ComputingService>()
.BuildServiceProvider();

await using var ipcServer = new IpcServer()
{
ServiceProvider = serviceProvider,
Scheduler = new ConcurrentExclusiveSchedulerPair().ExclusiveScheduler,
Endpoints = new()
{
{ typeof(IComputingService) },
},
Transport = serverTransport,
};
ipcServer.Start();
await ipcServer.WaitForStop();
Transport = serverTransport,
};
ipcServer.Start();
await Task.Delay(Timeout.InfiniteTimeSpan, ct);

return 0;
return 0;
}

static IDisposable ConsoleCancellation(out CancellationToken ct)
{
var cts = new CancellationTokenSource();
ct = cts.Token;
Console.CancelKeyPress += (sender, e) =>
{
e.Cancel = true;
cts.Cancel();
};
return cts;
}

0 comments on commit 59fe065

Please sign in to comment.