File tree 1 file changed +15
-13
lines changed
1 file changed +15
-13
lines changed Original file line number Diff line number Diff line change @@ -325,25 +325,27 @@ public void finalize() throws Throwable {
325
325
}
326
326
}
327
327
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
-
339
328
public void testJavaRefKeep () {
340
329
finalizedAnI = false ;
341
330
AnI obj = new AnI_Traced ();
342
331
Testpkg .callF (obj );
332
+ assertTrue ("want F to be called" , obj .calledF );
343
333
Testpkg .callF (obj );
344
334
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
+ }
347
349
348
350
finalizedAnI = false ;
349
351
obj = new AnI_Traced ();
You can’t perform that action at this time.
0 commit comments