Skip to content

Commit 8658322

Browse files
committed
removed code testing possiblity to dispose objects after domain restart
1 parent 913e429 commit 8658322

File tree

1 file changed

+0
-110
lines changed

1 file changed

+0
-110
lines changed

src/embed_tests/TestDomainReload.cs

-110
Original file line numberDiff line numberDiff line change
@@ -179,116 +179,6 @@ public static void CrossDomainObject()
179179

180180
#endregion
181181

182-
#region Tempary tests
183-
184-
// https://github.com/pythonnet/pythonnet/pull/1074#issuecomment-596139665
185-
[Test]
186-
public void CrossReleaseBuiltinType()
187-
{
188-
void ExecTest()
189-
{
190-
try
191-
{
192-
PythonEngine.Initialize();
193-
var numRef = CreateNumReference();
194-
Assert.True(numRef.IsAlive);
195-
PythonEngine.Shutdown(); // <- "run" 1 ends
196-
PythonEngine.Initialize(); // <- "run" 2 starts
197-
198-
GC.Collect();
199-
GC.WaitForPendingFinalizers(); // <- this will put former `num` into Finalizer queue
200-
Finalizer.Instance.Collect();
201-
// ^- this will call PyObject.Dispose, which will call XDecref on `num.Handle`,
202-
// but Python interpreter from "run" 1 is long gone, so it will corrupt memory instead.
203-
Assert.False(numRef.IsAlive);
204-
}
205-
finally
206-
{
207-
PythonEngine.Shutdown();
208-
}
209-
}
210-
211-
var errorArgs = new List<Finalizer.ErrorArgs>();
212-
void ErrorHandler(object sender, Finalizer.ErrorArgs e)
213-
{
214-
errorArgs.Add(e);
215-
}
216-
Finalizer.Instance.ErrorHandler += ErrorHandler;
217-
try
218-
{
219-
for (int i = 0; i < 10; i++)
220-
{
221-
ExecTest();
222-
}
223-
}
224-
finally
225-
{
226-
Finalizer.Instance.ErrorHandler -= ErrorHandler;
227-
}
228-
Assert.AreEqual(errorArgs.Count, 0);
229-
}
230-
231-
[Test]
232-
public void CrossReleaseCustomType()
233-
{
234-
void ExecTest()
235-
{
236-
try
237-
{
238-
PythonEngine.Initialize();
239-
var objRef = CreateConcreateObject();
240-
Assert.True(objRef.IsAlive);
241-
PythonEngine.Shutdown(); // <- "run" 1 ends
242-
PythonEngine.Initialize(); // <- "run" 2 starts
243-
GC.Collect();
244-
GC.WaitForPendingFinalizers();
245-
Finalizer.Instance.Collect();
246-
Assert.False(objRef.IsAlive);
247-
}
248-
finally
249-
{
250-
PythonEngine.Shutdown();
251-
}
252-
}
253-
254-
var errorArgs = new List<Finalizer.ErrorArgs>();
255-
void ErrorHandler(object sender, Finalizer.ErrorArgs e)
256-
{
257-
errorArgs.Add(e);
258-
}
259-
Finalizer.Instance.ErrorHandler += ErrorHandler;
260-
try
261-
{
262-
for (int i = 0; i < 10; i++)
263-
{
264-
ExecTest();
265-
}
266-
}
267-
finally
268-
{
269-
Finalizer.Instance.ErrorHandler -= ErrorHandler;
270-
}
271-
Assert.AreEqual(errorArgs.Count, 0);
272-
}
273-
274-
private static WeakReference CreateNumReference()
275-
{
276-
var num = 3216757418.ToPython();
277-
Assert.AreEqual(num.Refcount, 1);
278-
WeakReference numRef = new WeakReference(num, false);
279-
return numRef;
280-
}
281-
282-
private static WeakReference CreateConcreateObject()
283-
{
284-
var obj = new Domain.MyClass().ToPython();
285-
Assert.AreEqual(obj.Refcount, 1);
286-
WeakReference numRef = new WeakReference(obj, false);
287-
return numRef;
288-
}
289-
290-
#endregion Tempary tests
291-
292182
/// <summary>
293183
/// This is a magic incantation required to run code in an application
294184
/// domain other than the current one.

0 commit comments

Comments
 (0)