Skip to content

Commit f2ef6f4

Browse files
committed
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 <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]>
1 parent a4d62f3 commit f2ef6f4

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

bind/java/SeqTest.java

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -325,25 +325,27 @@ public void finalize() throws Throwable {
325325
}
326326
}
327327

328-
public void testJavaRefGC() {
329-
finalizedAnI = false;
330-
AnI obj = new AnI_Traced();
331-
Testpkg.callF(obj);
332-
assertTrue("want F to be called", obj.calledF);
333-
Testpkg.callF(obj);
334-
obj = null;
335-
runGC();
336-
assertTrue("want obj to be collected", finalizedAnI);
337-
}
338-
339328
public void testJavaRefKeep() {
340329
finalizedAnI = false;
341330
AnI obj = new AnI_Traced();
342331
Testpkg.callF(obj);
332+
assertTrue("want F to be called", obj.calledF);
343333
Testpkg.callF(obj);
344334
obj = null;
345-
runGC();
346-
assertTrue("want obj not to be kept by Go", finalizedAnI);
335+
int attempts = 0;
336+
while (true) {
337+
runGC();
338+
if (finalizedAnI)
339+
break;
340+
attempts++;
341+
try {
342+
Thread.sleep(100);
343+
} catch (InterruptedException e) {
344+
throw new RuntimeException(e);
345+
}
346+
if (attempts >= 10)
347+
fail("want obj not to be kept by Go; tried " + attempts + " garbage collections.");
348+
}
347349

348350
finalizedAnI = false;
349351
obj = new AnI_Traced();

0 commit comments

Comments
 (0)