bind/java: deflake testJavaRefKeep

Retry a few times to ensure the garbage collector collects what
we expect. Also merge and remove testJavaRefGC which was identical
except for one line.

Updates golang/go#30785

Change-Id: Id6c541b41fe483633c40eeea712c1f43b647e4f4
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/167657
Run-TryBot: Elias Naur <mail@eliasnaur.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
Elias Naur
2019-03-14 16:44:39 +00:00
parent a4d62f3683
commit f2ef6f42b7
+15 -13
View File
@@ -325,25 +325,27 @@ public class SeqTest extends InstrumentationTestCase {
}
}
public void testJavaRefGC() {
public void testJavaRefKeep() {
finalizedAnI = false;
AnI obj = new AnI_Traced();
Testpkg.callF(obj);
assertTrue("want F to be called", obj.calledF);
Testpkg.callF(obj);
obj = null;
runGC();
assertTrue("want obj to be collected", finalizedAnI);
}
public void testJavaRefKeep() {
finalizedAnI = false;
AnI obj = new AnI_Traced();
Testpkg.callF(obj);
Testpkg.callF(obj);
obj = null;
runGC();
assertTrue("want obj not to be kept by Go", finalizedAnI);
int attempts = 0;
while (true) {
runGC();
if (finalizedAnI)
break;
attempts++;
try {
Thread.sleep(100);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
if (attempts >= 10)
fail("want obj not to be kept by Go; tried " + attempts + " garbage collections.");
}
finalizedAnI = false;
obj = new AnI_Traced();