mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-20 14:49:53 +01:00
Speed up BridgeTest by only retrying bridges that have failed.
This commit is contained in:
@@ -30,6 +30,7 @@ import org.junit.runners.Parameterized.Parameters;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
@@ -198,6 +199,11 @@ public class BridgeTest extends BrambleTestCase {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBridges() throws Exception {
|
public void testBridges() throws Exception {
|
||||||
|
if (params.stats.hasSucceeded(params.bridge)) {
|
||||||
|
LOG.info("Skipping previously successful bridge: " + params.bridge);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
DuplexPlugin duplexPlugin =
|
DuplexPlugin duplexPlugin =
|
||||||
factory.createPlugin(new TestPluginCallback());
|
factory.createPlugin(new TestPluginCallback());
|
||||||
assertNotNull(duplexPlugin);
|
assertNotNull(duplexPlugin);
|
||||||
@@ -209,10 +215,13 @@ public class BridgeTest extends BrambleTestCase {
|
|||||||
long start = clock.currentTimeMillis();
|
long start = clock.currentTimeMillis();
|
||||||
long timeout = params.bridgeType == MEEK ? MEEK_TIMEOUT : TIMEOUT;
|
long timeout = params.bridgeType == MEEK ? MEEK_TIMEOUT : TIMEOUT;
|
||||||
while (clock.currentTimeMillis() - start < timeout) {
|
while (clock.currentTimeMillis() - start < timeout) {
|
||||||
if (plugin.getState() == ACTIVE) return;
|
if (plugin.getState() == ACTIVE) break;
|
||||||
clock.sleep(500);
|
clock.sleep(500);
|
||||||
}
|
}
|
||||||
if (plugin.getState() != ACTIVE) {
|
if (plugin.getState() == ACTIVE) {
|
||||||
|
LOG.info("Connected to Tor: " + params.bridge);
|
||||||
|
params.stats.countSuccess(params.bridge);
|
||||||
|
} else {
|
||||||
LOG.warning("Could not connect to Tor within timeout: "
|
LOG.warning("Could not connect to Tor within timeout: "
|
||||||
+ params.bridge);
|
+ params.bridge);
|
||||||
params.stats.countFailure(params.bridge, params.essential);
|
params.stats.countFailure(params.bridge, params.essential);
|
||||||
@@ -240,11 +249,21 @@ public class BridgeTest extends BrambleTestCase {
|
|||||||
|
|
||||||
private static class Stats {
|
private static class Stats {
|
||||||
|
|
||||||
|
@GuardedBy("this")
|
||||||
|
private final Set<String> successes = new HashSet<>();
|
||||||
@GuardedBy("this")
|
@GuardedBy("this")
|
||||||
private final Multiset<String> failures = new Multiset<>();
|
private final Multiset<String> failures = new Multiset<>();
|
||||||
@GuardedBy("this")
|
@GuardedBy("this")
|
||||||
private final Set<String> unreachable = new TreeSet<>();
|
private final Set<String> unreachable = new TreeSet<>();
|
||||||
|
|
||||||
|
private synchronized boolean hasSucceeded(String bridge) {
|
||||||
|
return successes.contains(bridge);
|
||||||
|
}
|
||||||
|
|
||||||
|
private synchronized void countSuccess(String bridge) {
|
||||||
|
successes.add(bridge);
|
||||||
|
}
|
||||||
|
|
||||||
private synchronized void countFailure(String bridge,
|
private synchronized void countFailure(String bridge,
|
||||||
boolean essential) {
|
boolean essential) {
|
||||||
if (failures.add(bridge) == ATTEMPTS_PER_BRIDGE) {
|
if (failures.add(bridge) == ATTEMPTS_PER_BRIDGE) {
|
||||||
|
|||||||
Reference in New Issue
Block a user