Java/C# smart pointer tests: Give GC more time to collect objects

This commit is contained in:
William S Fulton 2014-03-15 23:39:37 +00:00
commit 87963d2e68
6 changed files with 137 additions and 67 deletions

View file

@ -15,7 +15,7 @@ public class li_std_auto_ptr_runme {
System.gc();
System.runFinalization();
try {
java.lang.Thread.sleep(1);
java.lang.Thread.sleep(10);
} catch (java.lang.InterruptedException e) {
}
}
@ -31,18 +31,38 @@ public class li_std_auto_ptr_runme {
throw new RuntimeException("number of objects should be 2");
k1 = null;
WaitForGC();
if (Klass.getTotal_count() != 1)
throw new RuntimeException("number of objects should be 1");
{
int countdown = 500;
int expectedCount = 1;
while (true) {
WaitForGC();
if (--countdown == 0)
break;
if (Klass.getTotal_count() == expectedCount)
break;
}
int actualCount = Klass.getTotal_count();
if (actualCount != expectedCount)
throw new RuntimeException("Expected count: " + expectedCount + " Actual count: " + actualCount);
}
if (!k2.getLabel().equals("second"))
throw new RuntimeException("wrong object label");
k2 = null;
WaitForGC();
if (Klass.getTotal_count() != 0)
throw new RuntimeException("no objects should be left");
{
int countdown = 500;
int expectedCount = 0;
while (true) {
WaitForGC();
if (--countdown == 0)
break;
if (Klass.getTotal_count() == expectedCount)
break;
};
int actualCount = Klass.getTotal_count();
if (actualCount != expectedCount)
throw new RuntimeException("Expected count: " + expectedCount + " Actual count: " + actualCount);
}
}
}