Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NativeAOT] Fix System.Collections.Immutable.Tests #84552

Merged
merged 5 commits into from
Apr 11, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,25 @@ namespace Microsoft.Extensions.Hosting
{
public class WindowsServiceLifetimeTests
{
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsPrivilegedProcess))]
private static bool IsRemoteExecutorSupportedAndPrivilegedProcess => RemoteExecutor.IsSupported && PlatformDetection.IsPrivilegedProcess;

[ConditionalFact(nameof(IsRemoteExecutorSupportedAndPrivilegedProcess))]
public void ServiceStops()
{
using var serviceTester = WindowsServiceTester.Create(async () =>
{
var applicationLifetime = new ApplicationLifetime(NullLogger<ApplicationLifetime>.Instance);
using var lifetime = new WindowsServiceLifetime(
new HostingEnvironment(),
new HostingEnvironment(),
applicationLifetime,
NullLoggerFactory.Instance,
new OptionsWrapper<HostOptions>(new HostOptions()));

await lifetime.WaitForStartAsync(CancellationToken.None);

// would normally occur here, but WindowsServiceLifetime does not depend on it.
// applicationLifetime.NotifyStarted();

// will be signaled by WindowsServiceLifetime when SCM stops the service.
applicationLifetime.ApplicationStopping.WaitHandle.WaitOne();

Expand All @@ -53,14 +55,14 @@ public void ServiceStops()

serviceTester.Stop();
serviceTester.WaitForStatus(ServiceControllerStatus.Stopped);

serviceProcess.WaitForExit();

var status = serviceTester.QueryServiceStatus();
Assert.Equal(0, status.win32ExitCode);
}

[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsPrivilegedProcess))]
[ConditionalFact(nameof(IsRemoteExecutorSupportedAndPrivilegedProcess))]
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, ".NET Framework is missing the fix from https://github.com/dotnet/corefx/commit/3e68d791066ad0fdc6e0b81828afbd9df00dd7f8")]
public void ExceptionOnStartIsPropagated()
{
Expand All @@ -69,7 +71,7 @@ public void ExceptionOnStartIsPropagated()
using (var lifetime = ThrowingWindowsServiceLifetime.Create(throwOnStart: new Exception("Should be thrown")))
{
Assert.Equal(lifetime.ThrowOnStart,
await Assert.ThrowsAsync<Exception>(async () =>
await Assert.ThrowsAsync<Exception>(async () =>
await lifetime.WaitForStartAsync(CancellationToken.None)));
}
});
Expand All @@ -81,7 +83,7 @@ await Assert.ThrowsAsync<Exception>(async () =>
Assert.Equal(Interop.Errors.ERROR_EXCEPTION_IN_SERVICE, status.win32ExitCode);
}

[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsPrivilegedProcess))]
[ConditionalFact(nameof(IsRemoteExecutorSupportedAndPrivilegedProcess))]
public void ExceptionOnStopIsPropagated()
{
using var serviceTester = WindowsServiceTester.Create(async () =>
Expand All @@ -91,7 +93,7 @@ public void ExceptionOnStopIsPropagated()
await lifetime.WaitForStartAsync(CancellationToken.None);
lifetime.ApplicationLifetime.NotifyStopped();
Assert.Equal(lifetime.ThrowOnStop,
await Assert.ThrowsAsync<Exception>( async () =>
await Assert.ThrowsAsync<Exception>(async () =>
await lifetime.StopAsync(CancellationToken.None)));
}
});
Expand All @@ -103,19 +105,19 @@ await Assert.ThrowsAsync<Exception>( async () =>
Assert.Equal(Interop.Errors.ERROR_PROCESS_ABORTED, status.win32ExitCode);
}

[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsPrivilegedProcess))]
[ConditionalFact(nameof(IsRemoteExecutorSupportedAndPrivilegedProcess))]
public void CancelStopAsync()
{
using var serviceTester = WindowsServiceTester.Create(async () =>
{
var applicationLifetime = new ApplicationLifetime(NullLogger<ApplicationLifetime>.Instance);
using var lifetime = new WindowsServiceLifetime(
new HostingEnvironment(),
new HostingEnvironment(),
applicationLifetime,
NullLoggerFactory.Instance,
new OptionsWrapper<HostOptions>(new HostOptions()));
await lifetime.WaitForStartAsync(CancellationToken.None);

await Assert.ThrowsAsync<OperationCanceledException>(async () => await lifetime.StopAsync(new CancellationToken(true)));
});

Expand All @@ -126,7 +128,7 @@ public void CancelStopAsync()
Assert.Equal(Interop.Errors.ERROR_PROCESS_ABORTED, status.win32ExitCode);
}

[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsPrivilegedProcess))]
[ConditionalFact(nameof(IsRemoteExecutorSupportedAndPrivilegedProcess))]
public void ServiceCanStopItself()
{
using (var serviceTester = WindowsServiceTester.Create(async () =>
Expand Down Expand Up @@ -166,10 +168,10 @@ public void ServiceCanStopItself()

// service should start cleanly
serviceTester.Start();

// service will proceed to stopped without any error
serviceTester.WaitForStatus(ServiceControllerStatus.Stopped);

var status = serviceTester.QueryServiceStatus();
Assert.Equal(0, status.win32ExitCode);

Expand All @@ -191,7 +193,7 @@ lifetime stopped
""", logText);
}

[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsPrivilegedProcess))]
[ConditionalFact(nameof(IsRemoteExecutorSupportedAndPrivilegedProcess))]
public void ServiceSequenceIsCorrect()
{
using (var serviceTester = WindowsServiceTester.Create(() =>
Expand Down Expand Up @@ -229,7 +231,7 @@ public void ServiceSequenceIsCorrect()

serviceTester.Stop();
serviceTester.WaitForStatus(ServiceControllerStatus.Stopped);

var status = serviceTester.QueryServiceStatus();
Assert.Equal(0, status.win32ExitCode);

Expand Down Expand Up @@ -272,9 +274,9 @@ protected override void OnStop()

public class ThrowingWindowsServiceLifetime : WindowsServiceLifetime
{
public static ThrowingWindowsServiceLifetime Create(Exception throwOnStart = null, Exception throwOnStop = null) =>
public static ThrowingWindowsServiceLifetime Create(Exception throwOnStart = null, Exception throwOnStop = null) =>
new ThrowingWindowsServiceLifetime(
new HostingEnvironment(),
new HostingEnvironment(),
new ApplicationLifetime(NullLogger<ApplicationLifetime>.Instance),
NullLoggerFactory.Instance,
new OptionsWrapper<HostOptions>(new HostOptions()))
Expand All @@ -285,7 +287,7 @@ public static ThrowingWindowsServiceLifetime Create(Exception throwOnStart = nul

public ThrowingWindowsServiceLifetime(IHostEnvironment environment, ApplicationLifetime applicationLifetime, ILoggerFactory loggerFactory, IOptions<HostOptions> optionsAccessor) :
base(environment, applicationLifetime, loggerFactory, optionsAccessor)
{
{
ApplicationLifetime = applicationLifetime;
}

Expand Down
30 changes: 29 additions & 1 deletion src/libraries/System.Collections.Immutable/tests/default.rd.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,35 @@
</Method>
</Type>

<Type Name="Xunit.Sdk.AssertEqualityComparer`1[[System.Collections.Generic.HashSet`1[[System.Collections.Generic.KeyValuePair`2[[System.Collections.Frozen.Tests.SimpleNonComparableStruct,System.Collections.Immutable.Tests],[System.Int32,System.Private.CoreLib]],System.Private.CoreLib]],System.Private.CoreLib]]" Dynamic="Required All">
<Method Name="CompareTypedSets" Dynamic="Required All">
<GenericArgument Name="System.Collections.Generic.KeyValuePair`2[[System.Collections.Frozen.Tests.SimpleNonComparableStruct,System.Collections.Immutable.Tests],[System.Int32,System.Private.CoreLib]],System.Private.CoreLib" />
</Method>
</Type>

<Type Name="Xunit.Sdk.AssertEqualityComparer`1[[System.Collections.Generic.HashSet`1[[System.Collections.Generic.KeyValuePair`2[[System.ValueTuple`2[[System.Collections.Frozen.Tests.SimpleNonComparableStruct, System.Collections.Immutable.Tests],[System.Collections.Frozen.Tests.SimpleNonComparableStruct, System.Collections.Immutable.Tests]],System.Private.CoreLib],[System.Int32,System.Private.CoreLib]],System.Private.CoreLib]],System.Private.CoreLib]]" Dynamic="Required All">
<Method Name="CompareTypedSets" Dynamic="Required All">
<GenericArgument Name="System.Collections.Generic.KeyValuePair`2[[System.ValueTuple`2[[System.Collections.Frozen.Tests.SimpleNonComparableStruct, System.Collections.Immutable.Tests],[System.Collections.Frozen.Tests.SimpleNonComparableStruct, System.Collections.Immutable.Tests]],System.Private.CoreLib],[System.Int32,System.Private.CoreLib]],System.Private.CoreLib" />
</Method>
</Type>

<Type Name="Xunit.Sdk.AssertEqualityComparer`1[[System.Collections.Generic.HashSet`1[[System.ValueTuple`2[[System.Collections.Frozen.Tests.SimpleNonComparableStruct, System.Collections.Immutable.Tests],[System.Collections.Frozen.Tests.SimpleNonComparableStruct, System.Collections.Immutable.Tests]],System.Private.CoreLib]],System.Private.CoreLib]]" Dynamic="Required All">
<Method Name="CompareTypedSets" Dynamic="Required All">
<GenericArgument Name="System.ValueTuple`2[[System.Collections.Frozen.Tests.SimpleNonComparableStruct, System.Collections.Immutable.Tests],[System.Collections.Frozen.Tests.SimpleNonComparableStruct, System.Collections.Immutable.Tests]],System.Private.CoreLib" />
</Method>
</Type>

<Type Name="Xunit.Sdk.AssertEqualityComparer`1[[System.Collections.Generic.HashSet`1[[System.Collections.Frozen.Tests.SimpleNonComparableStruct, System.Collections.Immutable.Tests]],System.Private.CoreLib]]" Dynamic="Required All">
<Method Name="CompareTypedSets" Dynamic="Required All">
<GenericArgument Name="System.Collections.Frozen.Tests.SimpleNonComparableStruct, System.Collections.Immutable.Tests" />
</Method>
</Type>

<Type Name="Xunit.Sdk.AssertEqualityComparer`1+TypeErasedEqualityComparer[[System.Object,System.Private.CoreLib]]" Dynamic="Required All">
<Method Name="EqualsGeneric" Dynamic="Required All">
<GenericArgument Name="System.Collections.Frozen.Tests.SimpleNonComparableStruct, System.Collections.Immutable.Tests" />
</Method>
</Type>
</Assembly>

</Application>
</Directives>