Test more invalid values for ThreadPool.[Unsafe]RegisterWaitForSingleObject (dotnet...
authorFilip Navara <filip.navara@gmail.com>
Wed, 6 Feb 2019 14:58:10 +0000 (15:58 +0100)
committerStephen Toub <stoub@microsoft.com>
Wed, 6 Feb 2019 14:58:10 +0000 (09:58 -0500)
* Test more invalid values for ThreadPool.[Unsafe]RegisterWaitForSingleObject.

* Add checks for argument names in ArgumentOutOfRangeException.

* Disable failing test on NetFX.

Commit migrated from https://github.com/dotnet/corefx/commit/41948bf0fd29ad5b668f6479ae329c91aeb31f32

src/libraries/System.Threading.ThreadPool/tests/ThreadPoolTests.cs

index bc2a0fb..1d56aef 100644 (file)
@@ -345,19 +345,45 @@ namespace System.Threading.ThreadPools.Tests
             WaitOrTimerCallback callback = (state, timedOut) => { };
             Assert.Throws<ArgumentNullException>(() => ThreadPool.RegisterWaitForSingleObject(null, callback, null, 0, true));
             Assert.Throws<ArgumentNullException>(() => ThreadPool.RegisterWaitForSingleObject(waitHandle, null, null, 0, true));
-            Assert.Throws<ArgumentOutOfRangeException>(() =>
+            AssertExtensions.Throws<ArgumentOutOfRangeException>("millisecondsTimeOutInterval", () =>
                 ThreadPool.RegisterWaitForSingleObject(waitHandle, callback, null, -2, true));
-            Assert.Throws<ArgumentOutOfRangeException>(() =>
+            AssertExtensions.Throws<ArgumentOutOfRangeException>("millisecondsTimeOutInterval", () =>
                 ThreadPool.RegisterWaitForSingleObject(waitHandle, callback, null, (long)-2, true));
-            Assert.Throws<ArgumentOutOfRangeException>(() =>
+            if (!PlatformDetection.IsFullFramework) // netfx silently overflows the timeout
+            {
+                AssertExtensions.Throws<ArgumentOutOfRangeException>("millisecondsTimeOutInterval", () =>
+                    ThreadPool.RegisterWaitForSingleObject(waitHandle, callback, null, (long)int.MaxValue + 1, true));
+            }
+            AssertExtensions.Throws<ArgumentOutOfRangeException>("timeout", () =>
                 ThreadPool.RegisterWaitForSingleObject(waitHandle, callback, null, TimeSpan.FromMilliseconds(-2), true));
-            Assert.Throws<ArgumentOutOfRangeException>(() =>
+            AssertExtensions.Throws<ArgumentOutOfRangeException>("timeout", () =>
                 ThreadPool.RegisterWaitForSingleObject(
                     waitHandle,
                     callback,
                     null,
                     TimeSpan.FromMilliseconds((double)int.MaxValue + 1),
                     true));
+
+            Assert.Throws<ArgumentNullException>(() => ThreadPool.UnsafeRegisterWaitForSingleObject(null, callback, null, 0, true));
+            Assert.Throws<ArgumentNullException>(() => ThreadPool.UnsafeRegisterWaitForSingleObject(waitHandle, null, null, 0, true));
+            AssertExtensions.Throws<ArgumentOutOfRangeException>("millisecondsTimeOutInterval", () =>
+                ThreadPool.UnsafeRegisterWaitForSingleObject(waitHandle, callback, null, -2, true));
+            AssertExtensions.Throws<ArgumentOutOfRangeException>("millisecondsTimeOutInterval", () =>
+                ThreadPool.UnsafeRegisterWaitForSingleObject(waitHandle, callback, null, (long)-2, true));
+            if (!PlatformDetection.IsFullFramework) // netfx silently overflows the timeout
+            {
+                AssertExtensions.Throws<ArgumentOutOfRangeException>("millisecondsTimeOutInterval", () =>
+                    ThreadPool.UnsafeRegisterWaitForSingleObject(waitHandle, callback, null, (long)int.MaxValue + 1, true));
+            }
+            AssertExtensions.Throws<ArgumentOutOfRangeException>("timeout", () =>
+                ThreadPool.UnsafeRegisterWaitForSingleObject(waitHandle, callback, null, TimeSpan.FromMilliseconds(-2), true));
+            AssertExtensions.Throws<ArgumentOutOfRangeException>("timeout", () =>
+                ThreadPool.UnsafeRegisterWaitForSingleObject(
+                    waitHandle,
+                    callback,
+                    null,
+                    TimeSpan.FromMilliseconds((double)int.MaxValue + 1),
+                    true));
         }
     }
 }