Skip to content

Commit 389c4e5

Browse files
committed
Add NativeAOT smoke tests for resetting apartment state
1 parent 0416028 commit 389c4e5

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/tests/nativeaot/SmokeTests/UnitTests/Threading.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ internal static class Threading
1515

1616
public static int Run()
1717
{
18+
if (OperatingSystem.IsWindows())
19+
{
20+
Console.WriteLine(" ApartmentTests");
21+
ApartmentTests.ResetApartmentStatus();
22+
}
23+
1824
Console.WriteLine(" WaitSubsystemTests.DoubleSetOnEventWithTimedOutWaiterShouldNotStayInWaitersList");
1925
WaitSubsystemTests.DoubleSetOnEventWithTimedOutWaiterShouldNotStayInWaitersList();
2026

@@ -121,6 +127,26 @@ public static int Run()
121127
}
122128
}
123129

130+
internal static class ApartmentTests
131+
{
132+
[Fact]
133+
public static void ResetApartmentStatus()
134+
{
135+
Assert.Equal(ApartmentState.MTA, Thread.CurrentThread.GetApartmentState());
136+
137+
Thread.CurrentThread.SetApartmentState(ApartmentState.Unknown);
138+
Assert.Equal(ApartmentState.MTA, Thread.CurrentThread.GetApartmentState());
139+
140+
Thread.CurrentThread.SetApartmentState(ApartmentState.STA);
141+
Assert.Equal(ApartmentState.STA, Thread.CurrentThread.GetApartmentState());
142+
143+
Thread.CurrentThread.SetApartmentState(ApartmentState.Unknown);
144+
Assert.Equal(ApartmentState.MTA, Thread.CurrentThread.GetApartmentState());
145+
146+
Thread.CurrentThread.SetApartmentState(ApartmentState.MTA);
147+
}
148+
}
149+
124150
internal static class WaitSubsystemTests
125151
{
126152
private const int AcceptableEarlyWaitTerminationDiffMilliseconds = -100;

0 commit comments

Comments
 (0)