Warn instead of fail on issues with the garbage collector itself.
This commit is contained in:
Benedikt Reinartz 2019-06-20 19:29:20 +02:00 коммит произвёл GitHub
Родитель e4e16a422a
Коммит 2bc514f6c5
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
1 изменённых файлов: 18 добавлений и 6 удалений

Просмотреть файл

@ -45,7 +45,7 @@ namespace Python.EmbeddingTest
called = true;
};
Assert.IsFalse(called);
Assert.IsFalse(called, "The event handler was called before it was installed");
Finalizer.Instance.CollectOnce += handler;
WeakReference shortWeak;
@ -55,13 +55,25 @@ namespace Python.EmbeddingTest
}
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
{
@ -71,7 +83,7 @@ namespace Python.EmbeddingTest
{
Finalizer.Instance.CollectOnce -= handler;
}
Assert.IsTrue(called);
Assert.IsTrue(called, "The event handler was not called during finalization");
Assert.GreaterOrEqual(objectCount, 1);
}