From 525df491d99672b3bbc682ce4d4cc30d22d91934 Mon Sep 17 00:00:00 2001 From: Filip Navara Date: Thu, 24 Jan 2019 22:22:15 +0100 Subject: [PATCH 1/3] Test more invalid values for ThreadPool.[Unsafe]RegisterWaitForSingleObject. --- .../tests/ThreadPoolTests.cs | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/System.Threading.ThreadPool/tests/ThreadPoolTests.cs b/src/System.Threading.ThreadPool/tests/ThreadPoolTests.cs index bc2a0fb1720f..bbb0bbf951e1 100644 --- a/src/System.Threading.ThreadPool/tests/ThreadPoolTests.cs +++ b/src/System.Threading.ThreadPool/tests/ThreadPoolTests.cs @@ -349,6 +349,8 @@ public static void QueueRegisterNegativeTest() ThreadPool.RegisterWaitForSingleObject(waitHandle, callback, null, -2, true)); Assert.Throws(() => ThreadPool.RegisterWaitForSingleObject(waitHandle, callback, null, (long)-2, true)); + Assert.Throws(() => + ThreadPool.RegisterWaitForSingleObject(waitHandle, callback, null, (long)int.MaxValue + 1, true)); Assert.Throws(() => ThreadPool.RegisterWaitForSingleObject(waitHandle, callback, null, TimeSpan.FromMilliseconds(-2), true)); Assert.Throws(() => @@ -358,6 +360,24 @@ public static void QueueRegisterNegativeTest() null, TimeSpan.FromMilliseconds((double)int.MaxValue + 1), true)); + + Assert.Throws(() => ThreadPool.UnsafeRegisterWaitForSingleObject(null, callback, null, 0, true)); + Assert.Throws(() => ThreadPool.UnsafeRegisterWaitForSingleObject(waitHandle, null, null, 0, true)); + Assert.Throws(() => + ThreadPool.UnsafeRegisterWaitForSingleObject(waitHandle, callback, null, -2, true)); + Assert.Throws(() => + ThreadPool.UnsafeRegisterWaitForSingleObject(waitHandle, callback, null, (long)-2, true)); + Assert.Throws(() => + ThreadPool.UnsafeRegisterWaitForSingleObject(waitHandle, callback, null, (long)int.MaxValue + 1, true)); + Assert.Throws(() => + ThreadPool.UnsafeRegisterWaitForSingleObject(waitHandle, callback, null, TimeSpan.FromMilliseconds(-2), true)); + Assert.Throws(() => + ThreadPool.UnsafeRegisterWaitForSingleObject( + waitHandle, + callback, + null, + TimeSpan.FromMilliseconds((double)int.MaxValue + 1), + true)); } } } From d62500742b64126f3cf97ce5a326908219603f98 Mon Sep 17 00:00:00 2001 From: Filip Navara Date: Thu, 24 Jan 2019 22:55:38 +0100 Subject: [PATCH 2/3] Add checks for argument names in ArgumentOutOfRangeException. --- .../tests/ThreadPoolTests.cs | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/System.Threading.ThreadPool/tests/ThreadPoolTests.cs b/src/System.Threading.ThreadPool/tests/ThreadPoolTests.cs index bbb0bbf951e1..d344c47afd0c 100644 --- a/src/System.Threading.ThreadPool/tests/ThreadPoolTests.cs +++ b/src/System.Threading.ThreadPool/tests/ThreadPoolTests.cs @@ -345,15 +345,15 @@ public static void QueueRegisterNegativeTest() WaitOrTimerCallback callback = (state, timedOut) => { }; Assert.Throws(() => ThreadPool.RegisterWaitForSingleObject(null, callback, null, 0, true)); Assert.Throws(() => ThreadPool.RegisterWaitForSingleObject(waitHandle, null, null, 0, true)); - Assert.Throws(() => + AssertExtensions.Throws("millisecondsTimeOutInterval", () => ThreadPool.RegisterWaitForSingleObject(waitHandle, callback, null, -2, true)); - Assert.Throws(() => + AssertExtensions.Throws("millisecondsTimeOutInterval", () => ThreadPool.RegisterWaitForSingleObject(waitHandle, callback, null, (long)-2, true)); - Assert.Throws(() => + AssertExtensions.Throws("millisecondsTimeOutInterval", () => ThreadPool.RegisterWaitForSingleObject(waitHandle, callback, null, (long)int.MaxValue + 1, true)); - Assert.Throws(() => + AssertExtensions.Throws("timeout", () => ThreadPool.RegisterWaitForSingleObject(waitHandle, callback, null, TimeSpan.FromMilliseconds(-2), true)); - Assert.Throws(() => + AssertExtensions.Throws("timeout", () => ThreadPool.RegisterWaitForSingleObject( waitHandle, callback, @@ -363,15 +363,15 @@ public static void QueueRegisterNegativeTest() Assert.Throws(() => ThreadPool.UnsafeRegisterWaitForSingleObject(null, callback, null, 0, true)); Assert.Throws(() => ThreadPool.UnsafeRegisterWaitForSingleObject(waitHandle, null, null, 0, true)); - Assert.Throws(() => + AssertExtensions.Throws("millisecondsTimeOutInterval", () => ThreadPool.UnsafeRegisterWaitForSingleObject(waitHandle, callback, null, -2, true)); - Assert.Throws(() => + AssertExtensions.Throws("millisecondsTimeOutInterval", () => ThreadPool.UnsafeRegisterWaitForSingleObject(waitHandle, callback, null, (long)-2, true)); - Assert.Throws(() => + AssertExtensions.Throws("millisecondsTimeOutInterval", () => ThreadPool.UnsafeRegisterWaitForSingleObject(waitHandle, callback, null, (long)int.MaxValue + 1, true)); - Assert.Throws(() => + AssertExtensions.Throws("timeout", () => ThreadPool.UnsafeRegisterWaitForSingleObject(waitHandle, callback, null, TimeSpan.FromMilliseconds(-2), true)); - Assert.Throws(() => + AssertExtensions.Throws("timeout", () => ThreadPool.UnsafeRegisterWaitForSingleObject( waitHandle, callback, From 334cff541e5f95c2baa88ec6d35cdd67816ececb Mon Sep 17 00:00:00 2001 From: Filip Navara Date: Thu, 31 Jan 2019 15:46:44 +0100 Subject: [PATCH 3/3] Disable failing test on NetFX. --- .../tests/ThreadPoolTests.cs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/System.Threading.ThreadPool/tests/ThreadPoolTests.cs b/src/System.Threading.ThreadPool/tests/ThreadPoolTests.cs index d344c47afd0c..1d56aefca354 100644 --- a/src/System.Threading.ThreadPool/tests/ThreadPoolTests.cs +++ b/src/System.Threading.ThreadPool/tests/ThreadPoolTests.cs @@ -349,8 +349,11 @@ public static void QueueRegisterNegativeTest() ThreadPool.RegisterWaitForSingleObject(waitHandle, callback, null, -2, true)); AssertExtensions.Throws("millisecondsTimeOutInterval", () => ThreadPool.RegisterWaitForSingleObject(waitHandle, callback, null, (long)-2, true)); - AssertExtensions.Throws("millisecondsTimeOutInterval", () => - ThreadPool.RegisterWaitForSingleObject(waitHandle, callback, null, (long)int.MaxValue + 1, true)); + if (!PlatformDetection.IsFullFramework) // netfx silently overflows the timeout + { + AssertExtensions.Throws("millisecondsTimeOutInterval", () => + ThreadPool.RegisterWaitForSingleObject(waitHandle, callback, null, (long)int.MaxValue + 1, true)); + } AssertExtensions.Throws("timeout", () => ThreadPool.RegisterWaitForSingleObject(waitHandle, callback, null, TimeSpan.FromMilliseconds(-2), true)); AssertExtensions.Throws("timeout", () => @@ -367,8 +370,11 @@ public static void QueueRegisterNegativeTest() ThreadPool.UnsafeRegisterWaitForSingleObject(waitHandle, callback, null, -2, true)); AssertExtensions.Throws("millisecondsTimeOutInterval", () => ThreadPool.UnsafeRegisterWaitForSingleObject(waitHandle, callback, null, (long)-2, true)); - AssertExtensions.Throws("millisecondsTimeOutInterval", () => - ThreadPool.UnsafeRegisterWaitForSingleObject(waitHandle, callback, null, (long)int.MaxValue + 1, true)); + if (!PlatformDetection.IsFullFramework) // netfx silently overflows the timeout + { + AssertExtensions.Throws("millisecondsTimeOutInterval", () => + ThreadPool.UnsafeRegisterWaitForSingleObject(waitHandle, callback, null, (long)int.MaxValue + 1, true)); + } AssertExtensions.Throws("timeout", () => ThreadPool.UnsafeRegisterWaitForSingleObject(waitHandle, callback, null, TimeSpan.FromMilliseconds(-2), true)); AssertExtensions.Throws("timeout", () =>