Disable finalization of bogus SafeWaitHandles (dotnet/corefx#41636)
authorJan Kotas <jkotas@microsoft.com>
Tue, 8 Oct 2019 18:33:47 +0000 (11:33 -0700)
committerStephen Toub <stoub@microsoft.com>
Tue, 8 Oct 2019 18:33:47 +0000 (14:33 -0400)
Fixes dotnet/corefx#41635

Commit migrated from https://github.com/dotnet/corefx/commit/72f5cff116fdfa71f44090281e091b0dcbc31f8f

src/libraries/System.Runtime.Handles/tests/CriticalHandle.cs
src/libraries/System.Runtime.Handles/tests/SafeHandle.cs
src/libraries/System.Runtime.Handles/tests/SafeWaitHandle.cs
src/libraries/System.Runtime.Handles/tests/SafeWaitHandleExtensions.cs

index f4e5162..09f91b5 100644 (file)
@@ -6,7 +6,7 @@ using System;
 using System.Runtime.InteropServices;
 using Xunit;
 
-public partial class CriticalHandle_4000_Tests
+public partial class CriticalHandleTests
 {
     private class MyCriticalHandle : CriticalHandle
     {
index ab530ad..d401999 100644 (file)
@@ -6,7 +6,7 @@ using System;
 using System.Runtime.InteropServices;
 using Xunit;
 
-public partial class SafeHandle_4000_Tests
+public partial class SafeHandleTests
 {
     private class MySafeHandle : SafeHandle
     {
index 365078f..81bf40a 100644 (file)
@@ -6,7 +6,7 @@ using System;
 using Microsoft.Win32.SafeHandles;
 using Xunit;
 
-public partial class SafeWaitHandle_4000_Tests
+public partial class SafeWaitHandleTests
 {
     [Fact]
     public static void SafeWaitHandle_invalid()
@@ -22,5 +22,8 @@ public partial class SafeWaitHandle_4000_Tests
         SafeWaitHandle swh = new SafeWaitHandle(new IntPtr(1), true);
         Assert.False(swh.IsClosed);
         Assert.False(swh.IsInvalid);
+
+        // Prevent finalization. Closing of the bogus handle has unpredictable results.
+        swh.SetHandleAsInvalid();
     }
 }
index ad6fda6..99b5797 100644 (file)
@@ -7,7 +7,7 @@ using System;
 using System.Threading;
 using Xunit;
 
-public partial class SafeWaitHandleExtensions_4000_Tests
+public partial class SafeWaitHandleExtensionsTests
 {
     public class MyWaitHandle : WaitHandle
     {