Fix SemaphoreSlim validation in Wait/WaitAsync methods#121289
Fix SemaphoreSlim validation in Wait/WaitAsync methods#121289eduardo-vp merged 4 commits intodotnet:mainfrom
Conversation
|
Tagging subscribers to this area: @mangod9 |
There was a problem hiding this comment.
Pull Request Overview
This PR adds input validation for the millisecondsTimeout parameter to two overloads of Wait and WaitAsync methods in SemaphoreSlim, bringing them into alignment with other overloads that already perform this validation.
- Added
ArgumentOutOfRangeExceptionvalidation for negative timeout values (other than -1) inWait(int millisecondsTimeout)andWaitAsync(int millisecondsTimeout) - Added inline comments explaining the validation and subsequent method calls
src/libraries/System.Private.CoreLib/src/System/Threading/SemaphoreSlim.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Threading/SemaphoreSlim.cs
Outdated
Show resolved
Hide resolved
…phoreSlim.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…phoreSlim.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
What is the bug that this is fixing? Do we need to add tests for it? |
|
Those methods don't have validation now and are allowed to actually wait even if the The bug should have been caught in: runtime/src/libraries/System.Threading/tests/SemaphoreSlimTests.cs Lines 66 to 71 in 3083294 runtime/src/libraries/System.Threading/tests/SemaphoreSlimTests.cs Lines 199 to 225 in 3083294 Wait didn't throw an exception, it continued the test execution and asserted that the wait was successful and the count decremented. In this case the test can be fixed by updating the expected result of However the problem is that the code was expected to throw but it didn't and it never checked that the exception was not thrown. I believe this could potentially happen for other tests too. Shall we update the tests pattern to verify this? |
|
We do validate |
|
/ba-g unrelated errors, just adding some validation to some methods |
Fix range validation for some Wait/WaitAsync methods that take the timeout as an integer.