From 1b306a439295eaacb2f39d7af36d5aeb764c4b11 Mon Sep 17 00:00:00 2001 From: Eduard Dumitru Date: Wed, 12 Jun 2024 14:54:59 +0200 Subject: [PATCH] fixes --- src/CI/azp-initialization.yaml | 8 +++- src/CI/azp-nodejs.yaml | 2 +- src/CI/azp-start.yaml | 5 +-- .../Implementation/SystemService.cs | 17 +++----- src/UiPath.CoreIpc.Tests/NamedPipeTests.cs | 43 +++++++++++-------- src/UiPath.CoreIpc.Tests/SystemTests.cs | 2 +- src/UiPath.CoreIpc.Tests/TestBase.cs | 5 ++- .../UiPath.CoreIpc.Tests.csproj | 1 + src/UiPath.CoreIpc.Tests/WebSocketTests.cs | 2 +- 9 files changed, 47 insertions(+), 38 deletions(-) diff --git a/src/CI/azp-initialization.yaml b/src/CI/azp-initialization.yaml index 65ac8faa..d9cf3247 100644 --- a/src/CI/azp-initialization.yaml +++ b/src/CI/azp-initialization.yaml @@ -1,10 +1,14 @@ steps: + - powershell: | + Write-Host "##vso[task.setvariable variable=DotnetRuntimeVersion;]8.0.0" + Write-Host "##vso[task.setvariable variable=DOTNET_NOLOGO;]true" + displayName: 'Use .NET Runtime 8.0.0' - task: UseDotNet@2 - displayName: 'Use .NET SDK 5.0.408' + displayName: 'Use .NET SDK 8.x' inputs: packageType: 'sdk' - version: '5.0.408' + version: 8.x # Read $(Version) from the UiPath.CoreIpc.csproj file - powershell: | diff --git a/src/CI/azp-nodejs.yaml b/src/CI/azp-nodejs.yaml index 27f81a43..ee14c6bf 100644 --- a/src/CI/azp-nodejs.yaml +++ b/src/CI/azp-nodejs.yaml @@ -54,7 +54,7 @@ condition: succeededOrFailed() inputs: testRunner: JUnit - workingDir: $(NodeJS_ProjectPath) + workingDir: $(NodeJS_ProjectPath) testResultsFiles: './src/Clients/js/reports/test/web/test-results.xml' - task: PublishTestResults@2 diff --git a/src/CI/azp-start.yaml b/src/CI/azp-start.yaml index 39d42380..d51e5497 100644 --- a/src/CI/azp-start.yaml +++ b/src/CI/azp-start.yaml @@ -22,9 +22,8 @@ variables: stages: - stage: Build displayName: '🏭 Build' -jobs: - # The following 3 jobs will run in parallel: - + jobs: + # The following 3 jobs will run in parallel: - job: displayName: '.NET on Windows' pool: diff --git a/src/UiPath.CoreIpc.Tests/Implementation/SystemService.cs b/src/UiPath.CoreIpc.Tests/Implementation/SystemService.cs index e0b6f892..b295f617 100644 --- a/src/UiPath.CoreIpc.Tests/Implementation/SystemService.cs +++ b/src/UiPath.CoreIpc.Tests/Implementation/SystemService.cs @@ -36,11 +36,7 @@ public class SystemMessage : Message } public class CancelIoPipeMessage : Message { - public CancelIoPipeMessage(int delayScecondCancel = 0) - { - DelayScecondCancel = delayScecondCancel; - } - public int DelayScecondCancel { get; set; } + public int[]? MsDelays { get; set; } } public class SystemService : ISystemService { @@ -190,16 +186,17 @@ public async Task Echo(Stream input, CancellationToken cancellationToken public static extern bool CancelIoEx(IntPtr handle, IntPtr lpOverlapped); public async Task CancelIoPipe(CancelIoPipeMessage message = null, CancellationToken cancellationToken = default) { + Debug.WriteLine("###################### CancelIoPipe"); await Task.Delay(50); #if WINDOWS - var networkPropertyInfo = message.Client.GetType().GetProperty("Network", BindingFlags.NonPublic | BindingFlags.Instance); - var pipeStream = networkPropertyInfo.GetValue(message.Client, null) as PipeStream; + var serverFieldInfo = message.Client.GetType().GetField("_server", BindingFlags.NonPublic | BindingFlags.Instance); + var pipeStream = serverFieldInfo.GetValue(message.Client) as PipeStream; var canceled = CancelIoEx(pipeStream.SafePipeHandle.DangerousGetHandle(), IntPtr.Zero); - - if (message.DelayScecondCancel > 0) + + foreach (var msDelay in message.MsDelays ?? []) { - await Task.Delay(message.DelayScecondCancel); + await Task.Delay(msDelay); canceled = CancelIoEx(pipeStream.SafePipeHandle.DangerousGetHandle(), IntPtr.Zero); } diff --git a/src/UiPath.CoreIpc.Tests/NamedPipeTests.cs b/src/UiPath.CoreIpc.Tests/NamedPipeTests.cs index 2d3219bd..9a7b80de 100644 --- a/src/UiPath.CoreIpc.Tests/NamedPipeTests.cs +++ b/src/UiPath.CoreIpc.Tests/NamedPipeTests.cs @@ -40,28 +40,35 @@ public async Task PipeSecurityForWindows() await CreateSystemService().DoNothing().ShouldThrowAsync(); } - [Fact] - public async Task PipeCancelIoOnServer_TwiceTightly() - { - //Two cancel with less than 1 second in between should fail - await _systemClient.CancelIoPipe(new(100)).ShouldThrowAsync(); - } + [Theory] + [InlineData(new int[0])] + [InlineData(100)] + [InlineData(1100)] + [InlineData(10, 10, 10, 10)] + public async Task PipeCancelIoOnServer_AnyNoOfTimes(params int[] msDelays) + { + // Any number of kernel32.CancelIoEx calls should not cause the client to give up on the connection. + (await _systemClient.CancelIoPipe(new() { MsDelays = msDelays })).ShouldBeTrue(); - [Fact] - public async Task PipeCancelIoOnClient() - { - (await _systemClient.Delay()).ShouldBeTrue(); + //Make sure the connection is still working + (await _systemClient.Delay()).ShouldBeTrue(); + } - var delayTask = _systemClient.Delay(500); - await Task.Delay(100); - var pipeStream = ((IpcProxy)_systemClient).Connection.Network as PipeStream; - SystemService.CancelIoEx(pipeStream.SafePipeHandle.DangerousGetHandle(), IntPtr.Zero).ShouldBeTrue(); + [Fact] + public async Task PipeCancelIoOnClient() + { + (await _systemClient.Delay()).ShouldBeTrue(); + + var delayTask = _systemClient.Delay(500); + await Task.Delay(100); + var pipeStream = ((IpcProxy)_systemClient).Connection.Network as PipeStream; + SystemService.CancelIoEx(pipeStream.SafePipeHandle.DangerousGetHandle(), IntPtr.Zero).ShouldBeTrue(); - (await delayTask).ShouldBeTrue(); + (await delayTask).ShouldBeTrue(); - //Make sure the connection is still working - (await _systemClient.Delay()).ShouldBeTrue(); - } + //Make sure the connection is still working + (await _systemClient.Delay()).ShouldBeTrue(); + } #endif } public class ComputingNamedPipeTests : ComputingTests> diff --git a/src/UiPath.CoreIpc.Tests/SystemTests.cs b/src/UiPath.CoreIpc.Tests/SystemTests.cs index e33832f4..cf9a97e1 100644 --- a/src/UiPath.CoreIpc.Tests/SystemTests.cs +++ b/src/UiPath.CoreIpc.Tests/SystemTests.cs @@ -5,7 +5,7 @@ namespace UiPath.CoreIpc.Tests; public abstract class SystemTests : TestBase where TBuilder : ServiceClientBuilder { protected ServiceHost _systemHost; - protected ISystemService _systemClient; + protected readonly ISystemService _systemClient; protected readonly SystemService _systemService; public SystemTests() { diff --git a/src/UiPath.CoreIpc.Tests/TestBase.cs b/src/UiPath.CoreIpc.Tests/TestBase.cs index 98d75a4e..567d7ecd 100644 --- a/src/UiPath.CoreIpc.Tests/TestBase.cs +++ b/src/UiPath.CoreIpc.Tests/TestBase.cs @@ -8,9 +8,10 @@ public abstract class TestBase : IDisposable protected static int Count = -1; public static readonly TimeSpan RequestTimeout = #if CI - TimeSpan.FromSeconds(2) + + TimeSpan.FromSeconds(3) + #endif - (Debugger.IsAttached ? TimeSpan.FromDays(1) : TimeSpan.FromSeconds(2)); + TimeSpan.FromSeconds(3); + // (Debugger.IsAttached ? TimeSpan.FromDays(1) : TimeSpan.FromSeconds(2)); protected readonly IServiceProvider _serviceProvider; protected readonly AsyncContext _guiThread = new AsyncContextThread().Context; diff --git a/src/UiPath.CoreIpc.Tests/UiPath.CoreIpc.Tests.csproj b/src/UiPath.CoreIpc.Tests/UiPath.CoreIpc.Tests.csproj index eaf03da6..dded2d78 100644 --- a/src/UiPath.CoreIpc.Tests/UiPath.CoreIpc.Tests.csproj +++ b/src/UiPath.CoreIpc.Tests/UiPath.CoreIpc.Tests.csproj @@ -6,6 +6,7 @@ $(DefineConstants);$(DefineConstantsEx) latest true + annotations diff --git a/src/UiPath.CoreIpc.Tests/WebSocketTests.cs b/src/UiPath.CoreIpc.Tests/WebSocketTests.cs index 0661160c..7cbb8abe 100644 --- a/src/UiPath.CoreIpc.Tests/WebSocketTests.cs +++ b/src/UiPath.CoreIpc.Tests/WebSocketTests.cs @@ -2,7 +2,7 @@ namespace UiPath.CoreIpc.Tests; public class SystemWebSocketTests : SystemTests> { - int _port = 1313 + GetCount(); + int _port = 51313 + GetCount(); HttpSysWebSocketsListener _listener; protected override ServiceHostBuilder Configure(ServiceHostBuilder serviceHostBuilder) {