From 2c61596871f17cbbd507f8fe2ef5bbbc81744d07 Mon Sep 17 00:00:00 2001 From: Ivan Vilata-i-Balaguer Date: Mon, 25 Apr 2016 11:15:05 +0200 Subject: [PATCH] Add property to check if network stress test thread report setup failure --- .../p2p/network/NetworkStressTest.java | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/network/src/test/java/io/bitsquare/p2p/network/NetworkStressTest.java b/network/src/test/java/io/bitsquare/p2p/network/NetworkStressTest.java index 3d8c39ca76..6a0a457353 100644 --- a/network/src/test/java/io/bitsquare/p2p/network/NetworkStressTest.java +++ b/network/src/test/java/io/bitsquare/p2p/network/NetworkStressTest.java @@ -3,6 +3,8 @@ package io.bitsquare.p2p.network; import io.bitsquare.p2p.NodeAddress; import io.bitsquare.p2p.P2PServiceListener; import io.bitsquare.p2p.seed.SeedNode; +import javafx.beans.property.BooleanProperty; +import javafx.beans.property.SimpleBooleanProperty; import org.jetbrains.annotations.NotNull; import org.junit.After; import org.junit.Before; @@ -25,7 +27,9 @@ public class NetworkStressTest { private SeedNode seedNode; @Before - public void setUp() throws IOException, InterruptedException { + public void setUp() throws Exception { + /** A property where threads can indicate setup failure. */ + BooleanProperty setupFailed = new SimpleBooleanProperty(false); /** A barrier to wait for concurrent tasks. */ final CountDownLatch pendingTasks = new CountDownLatch(1 /*seed node*/); @@ -38,7 +42,6 @@ public class NetworkStressTest { final boolean useLocalhost = true; final Set seedNodes = new HashSet<>(1); seedNodes.add(seedNodeAddress); // the only seed node in tests - boolean seedNodeSetupFailed = false; seedNode.createAndStartP2PService(seedNodeAddress, useLocalhost, 2 /*regtest*/, true /*detailed logging*/, seedNodes, new P2PServiceListener() { @@ -69,18 +72,25 @@ public class NetworkStressTest { @Override public void onHiddenServicePublished() { - pendingTasks.countDown(); // one less task to wait on + // successful result + pendingTasks.countDown(); } @Override public void onSetupFailed(Throwable throwable) { - //XXXX + // failed result + setupFailed.set(true); + pendingTasks.countDown(); } } ); // Wait for concurrent tasks to finish. pendingTasks.await(); + + // Check if nodes started correctly. + if (setupFailed.get()) + throw new Exception("nodes failed to start"); } @After