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() ...@@ -298,7 +298,7 @@ public async Task LeaksCollectedAndRePooled()
var anyContext = LeaksCollectedAndRePooled_Initialize(conn, ThreadCount); var anyContext = LeaksCollectedAndRePooled_Initialize(conn, ThreadCount);
// force collection of everything but `anyContext` // force collection of everything but `anyContext`
GC.Collect(3, GCCollectionMode.Forced, blocking: true); GC.Collect(3, GCCollectionMode.Forced);
GC.WaitForPendingFinalizers(); GC.WaitForPendingFinalizers();
await Task.Delay(TimeSpan.FromMinutes(1.01)).ForAwait(); await Task.Delay(TimeSpan.FromMinutes(1.01)).ForAwait();
......
...@@ -270,9 +270,6 @@ private void TestMassivePublish(ISubscriber conn, string channel, string caption ...@@ -270,9 +270,6 @@ private void TestMassivePublish(ISubscriber conn, string channel, string caption
{ {
const int loop = 10000; const int loop = 10000;
GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced);
GC.WaitForPendingFinalizers();
var tasks = new Task[loop]; var tasks = new Task[loop];
var withFAF = Stopwatch.StartNew(); var withFAF = Stopwatch.StartNew();
...@@ -282,9 +279,6 @@ private void TestMassivePublish(ISubscriber conn, string channel, string caption ...@@ -282,9 +279,6 @@ private void TestMassivePublish(ISubscriber conn, string channel, string caption
} }
withFAF.Stop(); withFAF.Stop();
GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced);
GC.WaitForPendingFinalizers();
var withAsync = Stopwatch.StartNew(); var withAsync = Stopwatch.StartNew();
for (int i = 0; i < loop; i++) for (int i = 0; i < loop; i++)
{ {
......
...@@ -464,7 +464,6 @@ public void CompareScriptToDirect() ...@@ -464,7 +464,6 @@ public void CompareScriptToDirect()
// run via script // run via script
db.KeyDelete(key, CommandFlags.FireAndForget); db.KeyDelete(key, CommandFlags.FireAndForget);
CollectGarbage();
var watch = Stopwatch.StartNew(); var watch = Stopwatch.StartNew();
for (int i = 1; i < LOOP; i++) // the i=1 is to do all-but-one for (int i = 1; i < LOOP; i++) // the i=1 is to do all-but-one
{ {
...@@ -476,7 +475,6 @@ public void CompareScriptToDirect() ...@@ -476,7 +475,6 @@ public void CompareScriptToDirect()
// run via raw op // run via raw op
db.KeyDelete(key, CommandFlags.FireAndForget); db.KeyDelete(key, CommandFlags.FireAndForget);
CollectGarbage();
watch = Stopwatch.StartNew(); watch = Stopwatch.StartNew();
for (int i = 1; i < LOOP; i++) // the i=1 is to do all-but-one for (int i = 1; i < LOOP; i++) // the i=1 is to do all-but-one
{ {
...@@ -750,9 +748,7 @@ public void PurgeLuaScriptOnFinalize() ...@@ -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, // 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 // and are thus available to be GC'd
_PurgeLuaScriptOnFinalize(Script); _PurgeLuaScriptOnFinalize(Script);
CollectGarbage();
GC.Collect(2, GCCollectionMode.Forced, blocking: true);
GC.WaitForPendingFinalizers();
Assert.Equal(0, LuaScript.GetCachedScriptCount()); Assert.Equal(0, LuaScript.GetCachedScriptCount());
......
...@@ -47,11 +47,9 @@ protected void Log(string message, params object[] args) ...@@ -47,11 +47,9 @@ protected void Log(string message, params object[] args)
protected void CollectGarbage() protected void CollectGarbage()
{ {
for (int i = 0; i < 3; i++) GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced);
{ GC.WaitForPendingFinalizers();
GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced); GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced);
GC.WaitForPendingFinalizers();
}
} }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1063:ImplementIDisposableCorrectly")] [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1063:ImplementIDisposableCorrectly")]
...@@ -113,7 +111,6 @@ protected void OnInternalError(object sender, InternalErrorEventArgs e) ...@@ -113,7 +111,6 @@ protected void OnInternalError(object sender, InternalErrorEventArgs e)
public void ClearAmbientFailures() public void ClearAmbientFailures()
{ {
Collect();
Interlocked.Exchange(ref privateFailCount, 0); Interlocked.Exchange(ref privateFailCount, 0);
lock (sharedFailCount) lock (sharedFailCount)
{ {
...@@ -135,18 +132,8 @@ public void SetExpectedAmbientFailureCount(int count) ...@@ -135,18 +132,8 @@ public void SetExpectedAmbientFailureCount(int count)
expectedFailCount = 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() public void Teardown()
{ {
Collect();
int sharedFails; int sharedFails;
lock (sharedFailCount) 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