Commit 77a3986a authored by Marc Gravell's avatar Marc Gravell

clarify MuxerIsCollected

parent 7171938d
...@@ -12,39 +12,39 @@ public class GarbageCollectionTests : TestBase ...@@ -12,39 +12,39 @@ public class GarbageCollectionTests : TestBase
private static void ForceGC() private static void ForceGC()
{ {
for(int i = 0; i < 3; i++) for (int i = 0; i < 3; i++)
{ {
GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced); GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced);
GC.WaitForPendingFinalizers(); GC.WaitForPendingFinalizers();
} }
} }
#if DEBUG
[Fact] [Fact]
public void MuxerIsCollected() public void MuxerIsCollected()
{ {
// first check WeakReference works like we expect // this is more nuanced than it looks; multiple sockets with
var obj = new object(); // async callbacks, plus a heartbeat on a timer
var wr = new WeakReference(obj);
obj = null;
ForceGC();
Assert.Null(wr.Target);
var muxer = Create(); // deliberately not "using" // deliberately not "using" - we *want* to leak this
muxer.GetDatabase().Ping(); var muxer = Create();
muxer.GetDatabase().Ping(); // smoke-test
ForceGC(); ForceGC();
int before = ConnectionMultiplexer.CollectedWithoutDispose;
wr = new WeakReference(muxer); #if DEBUG // this counter only exists in debug
int before = ConnectionMultiplexer.CollectedWithoutDispose;
#endif
var wr = new WeakReference(muxer);
muxer = null; muxer = null;
ForceGC(); ForceGC();
int after = ConnectionMultiplexer.CollectedWithoutDispose; // should be collectable
Assert.Null(wr.Target); Assert.Null(wr.Target);
#if DEBUG // this counter only exists in debug
int after = ConnectionMultiplexer.CollectedWithoutDispose;
Assert.Equal(before + 1, after); Assert.Equal(before + 1, after);
}
#endif #endif
}
} }
} }
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