Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
eduard-dumitru committed Jun 13, 2024
1 parent 753be9c commit 1b306a4
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 38 deletions.
8 changes: 6 additions & 2 deletions src/CI/azp-initialization.yaml
Original file line number Diff line number Diff line change
@@ -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: |
Expand Down
2 changes: 1 addition & 1 deletion src/CI/azp-nodejs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions src/CI/azp-start.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
17 changes: 7 additions & 10 deletions src/UiPath.CoreIpc.Tests/Implementation/SystemService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -190,16 +186,17 @@ public async Task<Stream> Echo(Stream input, CancellationToken cancellationToken
public static extern bool CancelIoEx(IntPtr handle, IntPtr lpOverlapped);
public async Task<bool> 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);
}

Expand Down
43 changes: 25 additions & 18 deletions src/UiPath.CoreIpc.Tests/NamedPipeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,28 +40,35 @@ public async Task PipeSecurityForWindows()
await CreateSystemService().DoNothing().ShouldThrowAsync<UnauthorizedAccessException>();
}

[Fact]
public async Task PipeCancelIoOnServer_TwiceTightly()
{
//Two cancel with less than 1 second in between should fail
await _systemClient.CancelIoPipe(new(100)).ShouldThrowAsync<IOException>();
}
[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<NamedPipeClientBuilder<IComputingService, IComputingCallback>>
Expand Down
2 changes: 1 addition & 1 deletion src/UiPath.CoreIpc.Tests/SystemTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace UiPath.CoreIpc.Tests;
public abstract class SystemTests<TBuilder> : TestBase where TBuilder : ServiceClientBuilder<TBuilder, ISystemService>
{
protected ServiceHost _systemHost;
protected ISystemService _systemClient;
protected readonly ISystemService _systemClient;
protected readonly SystemService _systemService;
public SystemTests()
{
Expand Down
5 changes: 3 additions & 2 deletions src/UiPath.CoreIpc.Tests/TestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
1 change: 1 addition & 0 deletions src/UiPath.CoreIpc.Tests/UiPath.CoreIpc.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<DefineConstants>$(DefineConstants);$(DefineConstantsEx)</DefineConstants>
<LangVersion>latest</LangVersion>
<ImplicitUsings>true</ImplicitUsings>
<Nullable>annotations</Nullable>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/UiPath.CoreIpc.Tests/WebSocketTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
namespace UiPath.CoreIpc.Tests;
public class SystemWebSocketTests : SystemTests<WebSocketClientBuilder<ISystemService>>
{
int _port = 1313 + GetCount();
int _port = 51313 + GetCount();
HttpSysWebSocketsListener _listener;
protected override ServiceHostBuilder Configure(ServiceHostBuilder serviceHostBuilder)
{
Expand Down

0 comments on commit 1b306a4

Please sign in to comment.