-
Notifications
You must be signed in to change notification settings - Fork 5k
Track test counts per execution. #115707
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
base: main
Are you sure you want to change the base?
Track test counts per execution. #115707
Conversation
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.
Pull Request Overview
This PR introduces functionality to track test counts per execution by recording and logging the number of test runs identified by a reference or ID. Key changes include:
- Adding the RecordTestRunCountSingle method to log individual test counts.
- Updating the StartTest method to increment test run counts and call the new logging method.
- Removing redundant test count increment logic from the StartTestWorker method.
foreach(var item in _testRunCounter) | ||
{ | ||
if(item.Key == refOrID) | ||
{ | ||
_logger.WriteToInstrumentationLog(_curTestSet, LoggingLevels.StartupShutdown, $"Run tests \"{item.Key}\" {item.Value} times."); | ||
} | ||
} |
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.
Instead of iterating over the entire _testRunCounter dictionary to find a matching key, consider using a direct dictionary lookup (e.g., TryGetValue) to improve performance.
foreach(var item in _testRunCounter) | |
{ | |
if(item.Key == refOrID) | |
{ | |
_logger.WriteToInstrumentationLog(_curTestSet, LoggingLevels.StartupShutdown, $"Run tests \"{item.Key}\" {item.Value} times."); | |
} | |
} | |
if (_testRunCounter.TryGetValue(refOrID, out var value)) | |
{ | |
_logger.WriteToInstrumentationLog(_curTestSet, LoggingLevels.StartupShutdown, $"Run tests \"{refOrID}\" {value} times."); | |
} |
Copilot uses AI. Check for mistakes.
StringBuilder sb = new(); | ||
lock (_testRunCounterLock) | ||
{ | ||
foreach(var item in _testRunCounter) | ||
{ | ||
if(item.Key == refOrID) | ||
{ | ||
_logger.WriteToInstrumentationLog(_curTestSet, LoggingLevels.StartupShutdown, $"Run tests \"{item.Key}\" {item.Value} times."); | ||
} | ||
} | ||
} | ||
|
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.
Refactor the loop in RecordTestRunCountSingle to use direct access of _testRunCounter by key, which will simplify the code and reduce the risk of missing the log when the key is absent.
StringBuilder sb = new(); | |
lock (_testRunCounterLock) | |
{ | |
foreach(var item in _testRunCounter) | |
{ | |
if(item.Key == refOrID) | |
{ | |
_logger.WriteToInstrumentationLog(_curTestSet, LoggingLevels.StartupShutdown, $"Run tests \"{item.Key}\" {item.Value} times."); | |
} | |
} | |
} | |
lock (_testRunCounterLock) | |
{ | |
if (_testRunCounter.TryGetValue(refOrID, out var value)) | |
{ | |
_logger.WriteToInstrumentationLog(_curTestSet, LoggingLevels.StartupShutdown, $"Run tests \"{refOrID}\" {value} times."); | |
} | |
} |
Copilot uses AI. Check for mistakes.
Tagging subscribers to this area: @dotnet/gc |
Copilot had good suggestions. also please add some description to the PR - is there already per test logging? if so what value does this add (was the current logging insufficient)? what does the log look like before and after your change? and etc. |
thanks for the feedback, I've updated the code and added some description to the PR. |
Previous code Tests ran counter by VincentBu · Pull Request #111145 · dotnet/runtime added test run counter which records how many times each test run and write them at the end of logging file. However it doesn't work when tests is killed by assert failures or other errors. This pr aims to record each time a test is completed.
the log before looks like:
after: