Test more invalid values for ThreadPool.[Unsafe]RegisterWaitForSingleObject#34818
Conversation
| ThreadPool.RegisterWaitForSingleObject(waitHandle, callback, null, -2, true)); | ||
| Assert.Throws<ArgumentOutOfRangeException>(() => | ||
| ThreadPool.RegisterWaitForSingleObject(waitHandle, callback, null, (long)-2, true)); | ||
| Assert.Throws<ArgumentOutOfRangeException>(() => |
There was a problem hiding this comment.
None of the existing ones or the new ones are validating the argument name stored in the exception. There is one in all of these cases, right? Can these checks be augmented to include that? That would likely mean changing them all to be AssertExtensions.Throws instead of Assert.Throws.
There was a problem hiding this comment.
Good point. I will add it.
There was a problem hiding this comment.
For some of the ArgumentNullExceptions CoreRT and CoreCLR return different values. CoreRT correctly returns the actual parameter names (eg. "callBack"). CoreCLR mimics the legacy value from .NET Framework even though it's technically wrong ("WaitOrTimerCallback").
I'll add it to places where it's not a problem, but I would prefer the rest to be addressed separately because it will either need exceptions for certain frameworks or modifying the behavior of CoreRT or CoreCLR.
There was a problem hiding this comment.
We should ideally fix CoreCLR's name - it's OK to correct it.
There was a problem hiding this comment.
I'll submit the CoreCLR fix and amend this PR.
stephentoub
left a comment
There was a problem hiding this comment.
One comment, otherwise LGTM.
072d335 to
a7a323e
Compare
a7a323e to
d625007
Compare
|
@dotnet-bot test this please |
|
It was broken on NetFX last time I checked. It may need a backport of the CLR fix. |
That's unlikely to happen. You'll need to adjust the test. |
Only thing I can do is to split it in two and skip the problematic part on NetFX. |
Which part is the problem? |
AssertExtensions.Throws<ArgumentOutOfRangeException>("millisecondsTimeOutInterval", () =>
ThreadPool.RegisterWaitForSingleObject(waitHandle, callback, null, (long)int.MaxValue + 1, true));It is silently truncated in NetFX (reference source): [System.Security.SecuritySafeCritical] // auto-generated
[MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable
public static RegisteredWaitHandle RegisterWaitForSingleObject( // throws RegisterWaitException
WaitHandle waitObject,
WaitOrTimerCallback callBack,
Object state,
long millisecondsTimeOutInterval,
bool executeOnlyOnce // NOTE: we do not allow other options that allow the callback to be queued as an APC
)
{
if (millisecondsTimeOutInterval < -1)
throw new ArgumentOutOfRangeException("millisecondsTimeOutInterval", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegOrNegative1"));
Contract.EndContractBlock();
StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
return RegisterWaitForSingleObject(waitObject,callBack,state,(UInt32)millisecondsTimeOutInterval,executeOnlyOnce,ref stackMark,true); |
|
Ok, then you can just surround that assert with: if (!PlatformDetection.IsFullFramework) // netfx silently overflows the timeout
{
...
} |
|
@dotnet-bot test UWP CoreCLR x64 Debug Build |
…Object (dotnet/corefx#34818) * Test more invalid values for ThreadPool.[Unsafe]RegisterWaitForSingleObject. * Add checks for argument names in ArgumentOutOfRangeException. * Disable failing test on NetFX. Commit migrated from dotnet/corefx@41948bf
Unit tests for dotnet/corert#6887.