Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 320d57a

Browse files
authored
Fixing test on uap by adding ExitCode to RemoteInvokeHandle (#28413)
Fixes #28400
1 parent 184bf47 commit 320d57a

File tree

4 files changed

+30
-8
lines changed

4 files changed

+30
-8
lines changed

src/CoreFx.Private.TestUtilities/ref/CoreFx.Private.TestUtilities.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ protected RemoteExecutorTestBase() { }
146146
public sealed partial class RemoteInvokeHandle : System.IDisposable
147147
{
148148
public RemoteInvokeHandle(System.Diagnostics.Process process, System.Diagnostics.RemoteInvokeOptions options, string assemblyName, string className, string methodName) { }
149+
public int ExitCode { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } }
149150
public System.Diagnostics.RemoteInvokeOptions Options { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } }
150151
public System.Diagnostics.Process Process { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } }
151152
public void Dispose() { }

src/CoreFx.Private.TestUtilities/src/System/Diagnostics/RemoteExecutorTestBase.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,27 @@ public RemoteInvokeHandle(Process process, RemoteInvokeOptions options, string a
195195
MethodName = methodName;
196196
}
197197

198+
private int _exitCode;
199+
public int ExitCode
200+
{
201+
get
202+
{
203+
if (!PlatformDetection.IsUap)
204+
{
205+
Process.WaitForExit();
206+
return Process.ExitCode;
207+
}
208+
return _exitCode;
209+
}
210+
internal set
211+
{
212+
if (!PlatformDetection.IsUap)
213+
{
214+
throw new PlatformNotSupportedException("ExitCode property can only be set in UWP");
215+
}
216+
_exitCode = value;
217+
}
218+
}
198219
public Process Process { get; set; }
199220
public RemoteInvokeOptions Options { get; private set; }
200221
public string AssemblyName { get; private set; }

src/CoreFx.Private.TestUtilities/src/System/Diagnostics/RemoteExecutorTestBase.uap.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ private static RemoteInvokeHandle RemoteInvoke(MethodInfo method, string[] args,
3636
// that the method to invoke is available because we're already running in this assembly.
3737
Type t = method.DeclaringType;
3838
Assembly a = t.GetTypeInfo().Assembly;
39+
int exitCode;
3940

4041
using (AppServiceConnection remoteExecutionService = new AppServiceConnection())
4142
{
@@ -65,12 +66,13 @@ private static RemoteInvokeHandle RemoteInvoke(MethodInfo method, string[] args,
6566
AppServiceResponse response = remoteExecutionService.SendMessageAsync(message).GetAwaiter().GetResult();
6667

6768
Assert.True(response.Status == AppServiceResponseStatus.Success, $"response.Status = {response.Status}");
68-
int res = (int)response.Message["Results"];
69-
Assert.True(!options.CheckExitCode || res == options.ExpectedExitCode, (string)response.Message["Log"] + Environment.NewLine + $"Returned Error code: {res}");
69+
exitCode = (int)response.Message["Results"];
70+
Assert.True(!options.CheckExitCode || exitCode == options.ExpectedExitCode, (string)response.Message["Log"] + Environment.NewLine + $"Returned Error code: {exitCode}");
7071
}
71-
7272
// RemoteInvokeHandle is not really needed in the UAP scenario but we use it just to have consistent interface as non UAP
73-
return new RemoteInvokeHandle(null, options, null, null, null);
73+
var handle = new RemoteInvokeHandle(null, options, null, null, null);
74+
handle.ExitCode = exitCode;
75+
return handle;
7476
}
7577
}
7678
}

src/System.Runtime/tests/System/StringGetHashCodeTests.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,15 @@ public class StringGetHashCodeTests : RemoteExecutorTestBase
2020
[MemberData(nameof(GetHashCode_TestData))]
2121
public void GetHashCodeWithStringComparer_UseSameStringInTwoProcesses_ReturnsDifferentHashCodes(int getHashCodeIndex)
2222
{
23-
Func<string, string, int> method = (parentHash, i) => { return int.Parse(parentHash) != s_GetHashCodes[int.Parse(i)]() ? SuccessExitCode : -1; };
23+
Func<string, string, int> method = (parentHash, i) => int.Parse(parentHash) != s_GetHashCodes[int.Parse(i)]() ? SuccessExitCode : -1;
2424
int parentHashCode = s_GetHashCodes[getHashCodeIndex]();
2525
int exitCode, retry = 0;
2626
do
2727
{
2828
// very small chance the child and parent hashcode are the same. To further reduce chance of collision we try up to 3 times
2929
using (RemoteInvokeHandle handle = RemoteInvoke(method, parentHashCode.ToString(), getHashCodeIndex.ToString(), new RemoteInvokeOptions { CheckExitCode = false }))
3030
{
31-
Process p = handle.Process;
32-
p.WaitForExit();
33-
exitCode = p.ExitCode;
31+
exitCode = handle.ExitCode;
3432
retry++;
3533
}
3634
} while (exitCode != SuccessExitCode && retry < 3);

0 commit comments

Comments
 (0)