csharp: fix some unit tests that rely on garbage collection
authorVitor Sousa <vitorsousa@expertisesolutions.com.br>
Fri, 12 Jul 2019 20:09:41 +0000 (17:09 -0300)
committerTaehyub Kim <taehyub.kim@samsung.com>
Wed, 17 Jul 2019 07:27:16 +0000 (16:27 +0900)
Summary:
Fix unit tests `TestEoInherit.inherited_collected` and
`TestFunctionPointers.set_callback_inherited_called_from_c`.

Iterate through garbage collection and EFL main loop more times to ensure that
allocated objects are really collected.

Also expand the test utility method `CollectAndIterate` to receive the number of
times to call the whole cleaning iteration process (not only the garbage
collection).

Test Plan: `meson test`

Reviewers: lauromoura

Reviewed By: lauromoura

Subscribers: cedric, #reviewers, #committers

Tags: #efl

Differential Revision: https://phab.enlightenment.org/D9271

src/tests/efl_mono/Eo.cs
src/tests/efl_mono/FunctionPointers.cs
src/tests/efl_mono/TestUtils.cs

index be66f08..aa3565d 100644 (file)
@@ -120,7 +120,7 @@ class TestEoInherit
     public static void inherited_collected()
     {
         var wref = CreateCollectableInherited();
-        Test.CollectAndIterate();
+        Test.CollectAndIterate(300, 10);
 
         Test.AssertNull(wref.Target);
     }
index 4536704..911e20e 100644 (file)
@@ -171,9 +171,7 @@ class TestFunctionPointers
         // Should release the handle to the wrapper allocated when calling set_callback from C.
         obj.SetCallback(twice);
 
-        GC.Collect();
-        GC.WaitForPendingFinalizers();
-        Efl.App.AppMain.Iterate();
+        Test.CollectAndIterate(300, 10);
 
         Test.Assert(obj.set_called, "set_callback override must have been called");
         Test.Assert(!obj.invoke_called, "invoke_callback must not have been called");
index 21b8ec7..bbc37b5 100644 (file)
@@ -200,14 +200,17 @@ public static class Test
     /// <summary>Runs a number of garbage collections and iterate the main loop.
     /// The iteration is needed to make sure objects collected in the GC thread
     /// are efl_unref'd in the main thread.</summary>
-    public static void CollectAndIterate(int iterations=1000)
+    public static void CollectAndIterate(int iterations=1000, int global_iterations=1)
     {
-        for (int i = 0; i < iterations; i++)
+        for (int g = 0; g < global_iterations; ++g)
         {
-            System.GC.Collect();
+            for (int i = 0; i < iterations; ++i)
+            {
+                System.GC.Collect();
+            }
+            System.GC.WaitForPendingFinalizers();
+            Efl.App.AppMain.Iterate();
         }
-        System.GC.WaitForPendingFinalizers();
-        Efl.App.AppMain.Iterate();
     }
 
 }