Sitelet https://github.com/microsoft/vstest/commit/038b6c583e0c9409b0820ee36564f54cecffda7c
Skip to content

Commit 038b6c5

Browse files
nohwndCopilot
andcommitted
Address review: remove misleading lock/comment, fix nullable
- Remove lock and non-parallel note from GetAggregatedRunStats (called once at end, not in parallel - lock was reverted before) - Keep TryGetValue and kvp iteration optimizations - Restore non-nullable Dictionary<string, IDiaSymbol> in FullSymbolReader Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent b4af0f9 commit 038b6c5

2 files changed

Lines changed: 12 additions & 16 deletions

File tree

‎src/Microsoft.TestPlatform.CrossPlatEngine/Client/Parallel/ParallelRunDataAggregator.cs‎

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -70,30 +70,25 @@ public ParallelRunDataAggregator(string runSettingsXml)
7070

7171
public string RunSettings { get; }
7272

73-
// Note: This method is called once at the end of the test run to aggregate results.
74-
// It is NOT called in parallel, so thread-safety optimizations here would be misleading.
7573
public ITestRunStatistics GetAggregatedRunStats()
7674
{
7775
var testOutcomeMap = new Dictionary<TestOutcome, long>();
7876
long totalTests = 0;
79-
lock (_dataUpdateSyncObject)
77+
if (_testRunStatsList.Count > 0)
8078
{
81-
if (_testRunStatsList.Count > 0)
79+
foreach (var runStats in _testRunStatsList)
8280
{
83-
foreach (var runStats in _testRunStatsList)
81+
// TODO: we get nullref here if the stats are empty.
82+
foreach (var kvp in runStats.Stats!)
8483
{
85-
// TODO: we get nullref here if the stats are empty.
86-
foreach (var kvp in runStats.Stats!)
84+
if (!testOutcomeMap.TryGetValue(kvp.Key, out long currentCount))
8785
{
88-
if (!testOutcomeMap.TryGetValue(kvp.Key, out long currentCount))
89-
{
90-
currentCount = 0;
91-
}
92-
93-
testOutcomeMap[kvp.Key] = currentCount + kvp.Value;
86+
currentCount = 0;
9487
}
95-
totalTests += runStats.ExecutedTests;
88+
89+
testOutcomeMap[kvp.Key] = currentCount + kvp.Value;
9690
}
91+
totalTests += runStats.ExecutedTests;
9792
}
9893
}
9994

‎src/Microsoft.TestPlatform.ObjectModel/Navigation/FullSymbolReader.cs‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,13 +379,14 @@ private void PopulateCacheForTypeAndMethodSymbols()
379379

380380
IDiaEnumSymbols? enumSymbols = null;
381381
IDiaSymbol? methodSymbol;
382-
Dictionary<string, IDiaSymbol>? methodSymbolsForType;
382+
Dictionary<string, IDiaSymbol> methodSymbolsForType;
383383

384384
try
385385
{
386386
typeSymbol.GetName(out string symbolName);
387-
if (_methodSymbols.TryGetValue(symbolName, out methodSymbolsForType))
387+
if (_methodSymbols.TryGetValue(symbolName, out var existingMethodSymbols))
388388
{
389+
methodSymbolsForType = existingMethodSymbols;
389390
if (methodSymbolsForType.TryGetValue(methodName, out var cachedMethodSymbol))
390391
{
391392
return cachedMethodSymbol;

0 commit comments

Comments
 (0)