From 34017e16f821dcd85d3264b135e2819a41c3e55d Mon Sep 17 00:00:00 2001 From: Mike Hearn Date: Mon, 17 Nov 2014 14:38:56 +0100 Subject: [PATCH] TestWithPeerGroup: don't stopAsync if the peergroup isn't running and update the class description. --- .../main/java/org/bitcoinj/testing/TestWithPeerGroup.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/org/bitcoinj/testing/TestWithPeerGroup.java b/core/src/main/java/org/bitcoinj/testing/TestWithPeerGroup.java index 0705aac1..f7a9fcc5 100644 --- a/core/src/main/java/org/bitcoinj/testing/TestWithPeerGroup.java +++ b/core/src/main/java/org/bitcoinj/testing/TestWithPeerGroup.java @@ -34,7 +34,9 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkState; /** - * Utility class that makes it easy to work with mock NetworkConnections in PeerGroups. + * You can derive from this class and call peerGroup.start() in your tests to get a functional PeerGroup that can be + * used with loopback peers created using connectPeer. This involves real TCP connections so is a pretty accurate + * mock, but means unit tests cannot be run simultaneously. */ public class TestWithPeerGroup extends TestWithNetworkConnections { protected static final NetworkParameters params = UnitTestParams.get(); @@ -72,7 +74,8 @@ public class TestWithPeerGroup extends TestWithNetworkConnections { super.tearDown(); blockJobs = false; Utils.finishMockSleep(); - peerGroup.stopAsync(); + if (peerGroup.isRunning()) + peerGroup.stopAsync(); } catch (Exception e) { throw new RuntimeException(e); }