Fix GC.KeepAlive test case
authorBruce Forstall <brucefo@microsoft.com>
Fri, 12 Jan 2018 00:22:55 +0000 (16:22 -0800)
committerBruce Forstall <brucefo@microsoft.com>
Fri, 12 Jan 2018 00:22:55 +0000 (16:22 -0800)
In the test, as written, a GC could sneak in between the GC.KeepAlive()
call and the subsequent line that checks whether the finalizer
has run, especially in GC stress modes. Simply move the GC.KeepAlive()
call down.

tests/src/CoreMangLib/cti/system/gc/gckeepalive.cs

index ed90465..c8aa542 100644 (file)
@@ -44,13 +44,13 @@ public class GCKeepAlive
             GC.WaitForPendingFinalizers();
             GC.Collect();
 
-            GC.KeepAlive(tc);
             if (TestClass.m_TestInt != 1)
             {
                 TestLibrary.TestFramework.LogError("001.1", "Calling KeepAlive can not prevent an object to be GCed");
                 TestLibrary.TestFramework.LogInformation("WARNING [LOCAL VARIABLE] TestClass.m_TestInt = " + TestClass.m_TestInt);
                 retVal = false;
             }
+            GC.KeepAlive(tc);
         }
         catch (Exception e)
         {