-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Fix watson buckets setting race condition #46636
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
127 changes: 127 additions & 0 deletions
127
src/tests/Regressions/coreclr/GitHub_45929/test45929.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,127 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System; | ||
| using System.Reflection; | ||
| using System.Runtime.ExceptionServices; | ||
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
|
|
||
| namespace test45929 | ||
| { | ||
| public class Program | ||
| { | ||
| static int Main(string[] _) | ||
| { | ||
| Console.WriteLine("The test started."); | ||
| Console.WriteLine("Progress:"); | ||
|
|
||
| ThreadPool.GetMinThreads(out int _, out int cptMin); | ||
| ThreadPool.SetMinThreads(3500, cptMin); | ||
|
|
||
| Test.Run(); | ||
|
|
||
| Console.WriteLine("Finished successfully"); | ||
|
|
||
| return 100; | ||
| } | ||
|
|
||
| class Test | ||
| { | ||
| readonly TestCore methods; | ||
| MethodInfo methodInfo; | ||
|
|
||
| public Test() | ||
| { | ||
| methods = new TestCore(); | ||
| methodInfo = GetMethod("ExceptionDispatchInfoCaptureThrow"); | ||
| if (methodInfo is null) | ||
| { | ||
| throw new InvalidOperationException("The methodInfo object is missing or empty."); | ||
| } | ||
| } | ||
|
|
||
| public static void Run() | ||
| { | ||
| long progress = 0; | ||
| var test = new Test(); | ||
| const int MaxCount = 1000000; | ||
| Parallel.For( | ||
| 0, | ||
| MaxCount, | ||
| new ParallelOptions() { MaxDegreeOfParallelism = Environment.ProcessorCount }, | ||
| i => | ||
| { | ||
| if (Interlocked.Increment(ref progress) % 10000 == 0) | ||
| { | ||
| Console.WriteLine($"{DateTime.Now} : {progress * 100D / MaxCount:000.0}%"); | ||
| } | ||
| test.Invoke(); | ||
| }); | ||
| } | ||
|
|
||
| public void Invoke() | ||
| { | ||
| try | ||
| { | ||
| methodInfo.Invoke(methods, null); | ||
| } | ||
| catch | ||
| { | ||
| // Ignore | ||
| } | ||
| } | ||
|
|
||
| static MethodInfo GetMethod(string methodName) | ||
| { | ||
| foreach (MethodInfo method in typeof(TestCore).GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly)) | ||
| { | ||
| if (methodName == method.Name) | ||
| { | ||
| return method; | ||
| } | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| class TestCore | ||
| { | ||
| const int ExpirySeconds = 1000; | ||
|
|
||
| // An exception instance that gets refreshed every ExpirySeconds. | ||
| (ExceptionDispatchInfo Exception, DateTime CacheExpiryDateTime) exceptionCache; | ||
|
|
||
| /// <summary> | ||
| /// Captures and throws the a cached instance of an exception. | ||
| /// </summary> | ||
| public void ExceptionDispatchInfoCaptureThrow() | ||
| { | ||
| var error = GetCachedError(); | ||
| error.Throw(); | ||
| } | ||
|
|
||
| ExceptionDispatchInfo GetCachedError() | ||
| { | ||
| try | ||
| { | ||
| var cache = exceptionCache; | ||
| if (cache.Exception != null) | ||
| { | ||
| if (exceptionCache.CacheExpiryDateTime > DateTime.UtcNow) | ||
| { | ||
| return cache.Exception; | ||
| } | ||
| } | ||
| throw new Exception("Test"); | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| ExceptionDispatchInfo edi = ExceptionDispatchInfo.Capture(ex); | ||
| exceptionCache = (edi, DateTime.UtcNow.AddSeconds(ExpirySeconds)); | ||
| return edi; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: License header
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, all of my recent regression tests are missing licence header. I'll fix them.