Commit 9e4c0e5e authored by Nick Craver's avatar Nick Craver

Tests: tune when GC runs

It's only needed for a few tests, what we were doing was drastic overkill, especially with background concurrent GC in play these days.
parent a68ea655
......@@ -298,7 +298,7 @@ public async Task LeaksCollectedAndRePooled()
var anyContext = LeaksCollectedAndRePooled_Initialize(conn, ThreadCount);
// force collection of everything but `anyContext`
GC.Collect(3, GCCollectionMode.Forced, blocking: true);
GC.Collect(3, GCCollectionMode.Forced);
GC.WaitForPendingFinalizers();
await Task.Delay(TimeSpan.FromMinutes(1.01)).ForAwait();
......
......@@ -270,9 +270,6 @@ private void TestMassivePublish(ISubscriber conn, string channel, string caption
{
const int loop = 10000;
GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced);
GC.WaitForPendingFinalizers();
var tasks = new Task[loop];
var withFAF = Stopwatch.StartNew();
......@@ -282,9 +279,6 @@ private void TestMassivePublish(ISubscriber conn, string channel, string caption
}
withFAF.Stop();
GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced);
GC.WaitForPendingFinalizers();
var withAsync = Stopwatch.StartNew();
for (int i = 0; i < loop; i++)
{
......
......@@ -464,7 +464,6 @@ public void CompareScriptToDirect()
// run via script
db.KeyDelete(key, CommandFlags.FireAndForget);
CollectGarbage();
var watch = Stopwatch.StartNew();
for (int i = 1; i < LOOP; i++) // the i=1 is to do all-but-one
{
......@@ -476,7 +475,6 @@ public void CompareScriptToDirect()
// run via raw op
db.KeyDelete(key, CommandFlags.FireAndForget);
CollectGarbage();
watch = Stopwatch.StartNew();
for (int i = 1; i < LOOP; i++) // the i=1 is to do all-but-one
{
......@@ -750,9 +748,7 @@ public void PurgeLuaScriptOnFinalize()
// This has to be a separate method to guarantee that the created LuaScript objects go out of scope,
// and are thus available to be GC'd
_PurgeLuaScriptOnFinalize(Script);
GC.Collect(2, GCCollectionMode.Forced, blocking: true);
GC.WaitForPendingFinalizers();
CollectGarbage();
Assert.Equal(0, LuaScript.GetCachedScriptCount());
......
......@@ -46,12 +46,10 @@ protected void Log(string message, params object[] args)
}
protected void CollectGarbage()
{
for (int i = 0; i < 3; i++)
{
GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced);
GC.WaitForPendingFinalizers();
}
GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced);
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1063:ImplementIDisposableCorrectly")]
......@@ -113,7 +111,6 @@ protected void OnInternalError(object sender, InternalErrorEventArgs e)
public void ClearAmbientFailures()
{
Collect();
Interlocked.Exchange(ref privateFailCount, 0);
lock (sharedFailCount)
{
......@@ -135,18 +132,8 @@ public void SetExpectedAmbientFailureCount(int count)
expectedFailCount = count;
}
private static void Collect()
{
for (int i = 0; i < GC.MaxGeneration; i++)
{
GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced, true);
GC.WaitForPendingFinalizers();
}
}
public void Teardown()
{
Collect();
int sharedFails;
lock (sharedFailCount)
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment