Skip to content

Commit 3593082

Browse files
committed
Test use of IgnoringMessageHandler with ChannelManagerConstructor
1 parent 1d0c372 commit 3593082

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

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

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,18 @@ class HumanObjectPeerTestInstance {
2323
private final boolean break_cross_peer_refs;
2424
private final boolean use_nio_peer_handler;
2525
private final boolean use_filter;
26+
private final boolean use_ignore_handler;
2627
private final boolean use_chan_manager_constructor;
2728

28-
HumanObjectPeerTestInstance(boolean nice_close, boolean use_km_wrapper, boolean use_manual_watch, boolean reload_peers, boolean break_cross_peer_refs, boolean use_nio_peer_handler, boolean use_filter, boolean use_chan_manager_constructor) {
29+
HumanObjectPeerTestInstance(boolean nice_close, boolean use_km_wrapper, boolean use_manual_watch, boolean reload_peers, boolean break_cross_peer_refs, boolean use_nio_peer_handler, boolean use_filter, boolean use_ignore_handler, boolean use_chan_manager_constructor) {
2930
this.nice_close = nice_close;
3031
this.use_km_wrapper = use_km_wrapper;
3132
this.use_manual_watch = use_manual_watch;
3233
this.reload_peers = reload_peers;
3334
this.break_cross_peer_refs = break_cross_peer_refs;
3435
this.use_nio_peer_handler = use_nio_peer_handler;
3536
this.use_filter = use_filter;
37+
this.use_ignore_handler = use_ignore_handler;
3638
this.use_chan_manager_constructor = use_chan_manager_constructor;
3739
}
3840

@@ -296,8 +298,12 @@ private void bind_nio() {
296298
Peer(byte seed) {
297299
this(null, seed);
298300
if (use_chan_manager_constructor) {
301+
NetGraphMsgHandler route_handler = null;
302+
if (!use_ignore_handler) {
303+
route_handler = router;
304+
}
299305
this.constructor = new ChannelManagerConstructor(Network.LDKNetwork_Bitcoin, UserConfig.with_default(), new byte[32], 0,
300-
this.keys_interface, this.fee_estimator, this.chain_monitor, this.router, this.tx_broadcaster, this.logger);
306+
this.keys_interface, this.fee_estimator, this.chain_monitor, route_handler, this.tx_broadcaster, this.logger);
301307
constructor.chain_sync_completed(new ChannelManagerConstructor.ChannelManagerPersister() {
302308
@Override public void handle_event(Event event) {
303309
synchronized (pending_manager_events) {
@@ -875,14 +881,14 @@ protected void finalize() throws Throwable {
875881
}
876882
}
877883
public class HumanObjectPeerTest {
878-
HumanObjectPeerTestInstance do_test_run(boolean nice_close, boolean use_km_wrapper, boolean use_manual_watch, boolean reload_peers, boolean break_cross_peer_refs, boolean nio_peer_handler, boolean use_chan_manager_constructor) throws InterruptedException {
879-
HumanObjectPeerTestInstance instance = new HumanObjectPeerTestInstance(nice_close, use_km_wrapper, use_manual_watch, reload_peers, break_cross_peer_refs, nio_peer_handler, !nio_peer_handler, use_chan_manager_constructor);
884+
HumanObjectPeerTestInstance do_test_run(boolean nice_close, boolean use_km_wrapper, boolean use_manual_watch, boolean reload_peers, boolean break_cross_peer_refs, boolean nio_peer_handler, boolean use_ignoring_routing_handler, boolean use_chan_manager_constructor) throws InterruptedException {
885+
HumanObjectPeerTestInstance instance = new HumanObjectPeerTestInstance(nice_close, use_km_wrapper, use_manual_watch, reload_peers, break_cross_peer_refs, nio_peer_handler, !nio_peer_handler, use_ignoring_routing_handler, use_chan_manager_constructor);
880886
HumanObjectPeerTestInstance.TestState state = instance.do_test_message_handler();
881887
instance.do_test_message_handler_b(state);
882888
return instance;
883889
}
884-
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, boolean use_chan_manager_constructor) throws InterruptedException {
885-
HumanObjectPeerTestInstance instance = do_test_run(nice_close, use_km_wrapper, use_manual_watch, reload_peers, break_cross_peer_refs, nio_peer_handler, use_chan_manager_constructor);
890+
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, boolean use_ignoring_routing_handler, boolean use_chan_manager_constructor) throws InterruptedException {
891+
HumanObjectPeerTestInstance instance = do_test_run(nice_close, use_km_wrapper, use_manual_watch, reload_peers, break_cross_peer_refs, nio_peer_handler, use_ignoring_routing_handler, use_chan_manager_constructor);
886892
while (instance.gc_count != instance.gc_exp_count) {
887893
System.gc();
888894
System.runFinalization();
@@ -899,7 +905,8 @@ public void test_message_handler() throws InterruptedException {
899905
boolean reload_peers = (i & (1 << 3)) != 0;
900906
boolean break_cross_refs = (i & (1 << 4)) != 0;
901907
boolean nio_peer_handler = (i & (1 << 5)) != 0;
902-
boolean use_chan_manager_constructor = (i & (1 << 6)) != 0;
908+
boolean use_ignoring_routing_handler = (i & (1 << 6)) != 0;
909+
boolean use_chan_manager_constructor = (i & (1 << 7)) != 0;
903910
if (break_cross_refs && !reload_peers) {
904911
// There are no cross refs to break without reloading peers.
905912
continue;
@@ -908,8 +915,13 @@ public void test_message_handler() throws InterruptedException {
908915
// ChannelManagerConstructor requires a ChainMonitor as the Watch and creates a NioPeerHandler for us.
909916
continue;
910917
}
918+
if (!use_chan_manager_constructor && use_ignoring_routing_handler) {
919+
// We rely on the ChannelManagerConstructor to convert null into an IgnoringMessageHandler, so don't
920+
// try to run with an IgnoringMessageHandler unless we're also using a ChannelManagerConstructor.
921+
continue;
922+
}
911923
System.err.println("Running test with flags " + i);
912-
do_test(nice_close, use_km_wrapper, use_manual_watch, reload_peers, break_cross_refs, nio_peer_handler, use_chan_manager_constructor);
924+
do_test(nice_close, use_km_wrapper, use_manual_watch, reload_peers, break_cross_refs, nio_peer_handler, use_ignoring_routing_handler, use_chan_manager_constructor);
913925
}
914926
}
915927

0 commit comments

Comments
 (0)