Skip to content

Commit 29ab964

Browse files
committed
More aggressively check for full GC run during HumanObjectPeerTest
1 parent 061208b commit 29ab964

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/test/java/org/ldk/HumanObjectPeerTest.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ public MonitorEvent[] release_pending_monitor_events() {
174174
final HashMap<String, ChannelMonitor> monitors; // Wow I forgot just how terrible Java is - we can't put a byte array here.
175175
byte[] node_id;
176176
final LinkedList<byte[]> broadcast_set = new LinkedList<>();
177+
GcCheck obj = new GcCheck();
177178

178179
private TwoTuple<OutPoint, byte[]> test_mon_roundtrip(ChannelMonitor mon) {
179180
// Because get_funding_txo() returns an OutPoint in a tuple that is a reference to an OutPoint inside the
@@ -683,11 +684,13 @@ void do_test_message_handler_b(TestState state) {
683684
}
684685

685686
java.util.LinkedList<WeakReference<Object>> must_free_objs = new java.util.LinkedList();
686-
boolean gc_ran = false;
687+
int gc_count = 0;
688+
int gc_exp_count = 0;
687689
class GcCheck {
690+
GcCheck() { gc_exp_count += 1; }
688691
@Override
689692
protected void finalize() throws Throwable {
690-
gc_ran = true;
693+
gc_count += 1;
691694
super.finalize();
692695
}
693696
}
@@ -701,7 +704,7 @@ HumanObjectPeerTestInstance do_test_run(boolean nice_close, boolean use_km_wrapp
701704
}
702705
void do_test(boolean nice_close, boolean use_km_wrapper, boolean use_manual_watch, boolean reload_peers, boolean break_cross_peer_refs, boolean nio_peer_handler) throws InterruptedException {
703706
HumanObjectPeerTestInstance instance = do_test_run(nice_close, use_km_wrapper, use_manual_watch, reload_peers, break_cross_peer_refs, nio_peer_handler);
704-
while (!instance.gc_ran) {
707+
while (instance.gc_count != instance.gc_exp_count) {
705708
System.gc();
706709
System.runFinalization();
707710
}

0 commit comments

Comments
 (0)