10000 Fix the failing test by filmor · Pull Request #888 · pythonnet/pythonnet · GitHub
[go: up one dir, main page]

Skip to content

Fix the failing test #888

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 20, 2019
Merged
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
24 changes: 18 additions & 6 deletions src/embed_tests/TestFinalizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void CollectBasicObject()
called = true;
};

Assert.IsFalse(called);
Assert.IsFalse(called, "The event handler was called before it was installed");
Finalizer.Instance.CollectOnce += handler;

WeakReference shortWeak;
Expand All @@ -55,13 +55,25 @@ public void CollectBasicObject()
}
FullGCCollect();
// The object has been resurrected
Assert.IsFalse(shortWeak.IsAlive);
Assert.IsTrue(longWeak.IsAlive);
Warn.If(
shortWeak.IsAlive,
"The referenced object is alive although it should have been collected",
shortWeak
);
Assert.IsTrue(
longWeak.IsAlive,
"The reference object is not alive although it should still be",
longWeak
);

{
var garbage = Finalizer.Instance.GetCollectedObjects();
Assert.NotZero(garbage.Count);
Assert.IsTrue(garbage.Any(T => ReferenceEquals(T.Target, longWeak.Target)));
Assert.NotZero(garbage.Count, "There should still be garbage around");
Warn.Unless(
garbage.Any(T => ReferenceEquals(T.Target, longWeak.Target)),
$"The {nameof(longWeak)} reference doesn't show up in the garbage list",
garbage
);
}
try
{
Expand All @@ -71,7 +83,7 @@ public void CollectBasicObject()
{
Finalizer.Instance.CollectOnce -= handler;
}
Assert.IsTrue(called);
Assert.IsTrue(called, "The event handler was not called during finalization");
Assert.GreaterOrEqual(objectCount, 1);
}

Expand Down
0