mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-17 05:09:53 +01:00
Merge branch 'allow-one-unreachable-bridge' into 'master'
Allow BridgeTest to pass if one bridge is unreachable See merge request briar/briar!1449
This commit is contained in:
@@ -23,8 +23,10 @@ import org.junit.runners.Parameterized;
|
|||||||
import org.junit.runners.Parameterized.Parameters;
|
import org.junit.runners.Parameterized.Parameters;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
@@ -45,15 +47,22 @@ import static org.junit.Assume.assumeTrue;
|
|||||||
public class BridgeTest extends BrambleTestCase {
|
public class BridgeTest extends BrambleTestCase {
|
||||||
|
|
||||||
@Parameters
|
@Parameters
|
||||||
public static Iterable<String> data() {
|
public static Iterable<Params> data() {
|
||||||
BrambleJavaIntegrationTestComponent component =
|
BrambleJavaIntegrationTestComponent component =
|
||||||
DaggerBrambleJavaIntegrationTestComponent.builder().build();
|
DaggerBrambleJavaIntegrationTestComponent.builder().build();
|
||||||
BrambleCoreIntegrationTestEagerSingletons.Helper
|
BrambleCoreIntegrationTestEagerSingletons.Helper
|
||||||
.injectEagerSingletons(component);
|
.injectEagerSingletons(component);
|
||||||
return component.getCircumventionProvider().getBridges(false);
|
// Share a failure counter among all the test instances
|
||||||
|
AtomicInteger failures = new AtomicInteger(0);
|
||||||
|
List<String> bridges =
|
||||||
|
component.getCircumventionProvider().getBridges(false);
|
||||||
|
List<Params> states = new ArrayList<>(bridges.size());
|
||||||
|
for (String bridge : bridges) states.add(new Params(bridge, failures));
|
||||||
|
return states;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final static long TIMEOUT = SECONDS.toMillis(60);
|
private final static long TIMEOUT = SECONDS.toMillis(60);
|
||||||
|
private final static int NUM_FAILURES_ALLOWED = 1;
|
||||||
|
|
||||||
private final static Logger LOG = getLogger(BridgeTest.class.getName());
|
private final static Logger LOG = getLogger(BridgeTest.class.getName());
|
||||||
|
|
||||||
@@ -80,11 +89,13 @@ public class BridgeTest extends BrambleTestCase {
|
|||||||
|
|
||||||
private final File torDir = getTestDirectory();
|
private final File torDir = getTestDirectory();
|
||||||
private final String bridge;
|
private final String bridge;
|
||||||
|
private final AtomicInteger failures;
|
||||||
|
|
||||||
private UnixTorPluginFactory factory;
|
private UnixTorPluginFactory factory;
|
||||||
|
|
||||||
public BridgeTest(String bridge) {
|
public BridgeTest(Params params) {
|
||||||
this.bridge = bridge;
|
bridge = params.bridge;
|
||||||
|
failures = params.failures;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
@@ -152,10 +163,24 @@ public class BridgeTest extends BrambleTestCase {
|
|||||||
clock.sleep(500);
|
clock.sleep(500);
|
||||||
}
|
}
|
||||||
if (plugin.getState() != ACTIVE) {
|
if (plugin.getState() != ACTIVE) {
|
||||||
fail("Could not connect to Tor within timeout.");
|
LOG.warning("Could not connect to Tor within timeout");
|
||||||
|
if (failures.incrementAndGet() > NUM_FAILURES_ALLOWED) {
|
||||||
|
fail(failures.get() + " bridges are unreachable");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
plugin.stop();
|
plugin.stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static class Params {
|
||||||
|
|
||||||
|
private final String bridge;
|
||||||
|
private final AtomicInteger failures;
|
||||||
|
|
||||||
|
private Params(String bridge, AtomicInteger failures) {
|
||||||
|
this.bridge = bridge;
|
||||||
|
this.failures = failures;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user