Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public DiscoveryResultCache(long cacheSize, TimeSpan discoveredTestEventTimeout,
_lastUpdate = DateTime.UtcNow;
_cacheTimeout = discoveredTestEventTimeout;

_tests = new List<TestCase>();
_tests = new List<TestCase>(InitialCapacity(cacheSize));
TotalDiscoveredTests = 0;
}

Expand Down Expand Up @@ -112,11 +112,13 @@ public void AddTest(TestCase test)
{
// Pass on the buffer to the listener and clear the old one
_onReportTestCases(_tests);
_tests = new List<TestCase>();
_tests = new List<TestCase>(InitialCapacity(_cacheSize));
_lastUpdate = DateTime.UtcNow;

EqtTrace.Verbose("DiscoveryResultCache.AddTest: Notified the onReportTestCases callback.");
}
}
}

private static int InitialCapacity(long cacheSize) => (int)Math.Min(cacheSize, 512);
Comment thread
azat-msft marked this conversation as resolved.
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Threading;

Expand Down Expand Up @@ -60,12 +59,12 @@ internal class TestRunCache : ITestRunCache
/// <summary>
/// The test case currently in progress.
/// </summary>
private ICollection<TestCase> _inProgressTests;
private List<TestCase> _inProgressTests;

/// <summary>
/// Test results buffer
/// </summary>
private ICollection<TestResult> _testResults;
private List<TestResult> _testResults;

/// <summary>
/// Sync object
Expand Down Expand Up @@ -93,8 +92,8 @@ internal TestRunCache(long cacheSize, TimeSpan cacheTimeout, OnCacheHit onCacheH
_onCacheHit = onCacheHit;
_lastUpdate = DateTime.UtcNow;
_cacheTimeout = cacheTimeout;
_inProgressTests = new Collection<TestCase>();
_testResults = new Collection<TestResult>();
_inProgressTests = new List<TestCase>(InitialCapacity(cacheSize));
_testResults = new List<TestResult>(InitialCapacity(cacheSize));
_runStats = new Dictionary<TestOutcome, long>();
_syncObject = new object();

Expand Down Expand Up @@ -272,7 +271,10 @@ public ICollection<TestResult> GetLastChunk()
{
var lastChunk = _testResults;

_testResults = new Collection<TestResult>();
// GetLastChunk() is the end-of-run drain; no further results are expected after this
// call, so avoid pre-allocating capacity here. The replacement list exists only to keep
// the field non-null and will be allocated lazily if results somehow arrive afterwards.
_testResults = new List<TestResult>();

return lastChunk;
}
Expand Down Expand Up @@ -337,8 +339,8 @@ private void SendResults()
{
// Pass on the buffer to the listener and clear the old one
_onCacheHit(TestRunStatistics, _testResults, _inProgressTests);
_testResults = new Collection<TestResult>();
_inProgressTests = new Collection<TestCase>();
_testResults = new List<TestResult>(InitialCapacity(_cacheSize));
_inProgressTests = new List<TestCase>(InitialCapacity(_cacheSize));
_lastUpdate = DateTime.UtcNow;

// Reset the timer
Expand Down Expand Up @@ -371,4 +373,6 @@ private void RemoveInProgress(TestResult result)
}
}

private static int InitialCapacity(long cacheSize) => (int)Math.Min(cacheSize, 512);
Comment thread
azat-msft marked this conversation as resolved.

}
Loading