Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Test more invalid values for ThreadPool.[Unsafe]RegisterWaitForSingleObject#34818

Merged
stephentoub merged 3 commits into
dotnet:masterfrom
filipnavara:threadpooltest
Feb 6, 2019
Merged

Test more invalid values for ThreadPool.[Unsafe]RegisterWaitForSingleObject#34818
stephentoub merged 3 commits into
dotnet:masterfrom
filipnavara:threadpooltest

Conversation

@filipnavara
Copy link
Copy Markdown
Member

Unit tests for dotnet/corert#6887.

ThreadPool.RegisterWaitForSingleObject(waitHandle, callback, null, -2, true));
Assert.Throws<ArgumentOutOfRangeException>(() =>
ThreadPool.RegisterWaitForSingleObject(waitHandle, callback, null, (long)-2, true));
Assert.Throws<ArgumentOutOfRangeException>(() =>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I will add it.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should ideally fix CoreCLR's name - it's OK to correct it.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll submit the CoreCLR fix and amend this PR.

Copy link
Copy Markdown
Member

@stephentoub stephentoub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One comment, otherwise LGTM.

@stephentoub
Copy link
Copy Markdown
Member

@dotnet-bot test this please

@filipnavara
Copy link
Copy Markdown
Member Author

It was broken on NetFX last time I checked. It may need a backport of the CLR fix.

@stephentoub
Copy link
Copy Markdown
Member

It may need a backport of the CLR fix.

That's unlikely to happen. You'll need to adjust the test.

@filipnavara
Copy link
Copy Markdown
Member Author

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.

@stephentoub
Copy link
Copy Markdown
Member

Only thing I can do is to split it in two and skip the problematic part on NetFX.

Which part is the problem?

@filipnavara
Copy link
Copy Markdown
Member Author

filipnavara commented Jan 31, 2019

            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);

@stephentoub
Copy link
Copy Markdown
Member

stephentoub commented Jan 31, 2019

Ok, then you can just surround that assert with:

if (!PlatformDetection.IsFullFramework) // netfx silently overflows the timeout
{
    ...
}

@filipnavara
Copy link
Copy Markdown
Member Author

@dotnet-bot test UWP CoreCLR x64 Debug Build

Copy link
Copy Markdown
Member

@stephentoub stephentoub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@stephentoub stephentoub merged commit 41948bf into dotnet:master Feb 6, 2019
@filipnavara filipnavara deleted the threadpooltest branch February 6, 2019 15:01
@karelz karelz added this to the 3.0 milestone Mar 18, 2019
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
…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
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants