mirror of
https://github.com/netbirdio/gomobile-tvos-fork.git
synced 2026-05-22 18:43:29 -07:00
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:
+15
-13
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user