Skip to content
Snippets Groups Projects
Commit 9e506fc6 authored by akwizgran's avatar akwizgran
Browse files

Add basic bootstrapping test, make BridgeTest optional.

parent a68f313e
No related branches found
No related tags found
No related merge requests found
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="BridgeTest" type="GradleRunConfiguration"
factoryName="Gradle">
<ExternalSystemSettings>
<option name="env">
<map>
<entry key="OPTIONAL_TESTS" value="org.briarproject.onionwrapper.BridgeTest" />
</map>
</option>
<option name="executionName" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="externalSystemIdString" value="GRADLE" />
<option name="scriptParameters" value="" />
<option name="taskDescriptions">
<list />
</option>
<option name="taskNames">
<list>
<option value=":onionwrapper-java:test" />
<option value="--tests" />
<option value="&quot;org.briarproject.onionwrapper.BridgeTest&quot;" />
</list>
</option>
<option name="vmOptions" />
</ExternalSystemSettings>
<ExternalSystemDebugServerProcess>false</ExternalSystemDebugServerProcess>
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
<DebugAllEnabled>false</DebugAllEnabled>
<method v="2" />
</configuration>
</component>
\ No newline at end of file
......@@ -9,6 +9,7 @@ import java.util.logging.Logger;
import javax.annotation.Nullable;
import javax.annotation.concurrent.ThreadSafe;
import static java.util.Arrays.asList;
import static java.util.logging.Level.WARNING;
import static java.util.logging.Logger.getLogger;
......@@ -67,4 +68,10 @@ public class TestUtils {
else if (arch.equals("arm")) return "armhf";
return null;
}
public static boolean isOptionalTestEnabled(Class<?> testClass) {
String optionalTests = System.getenv("OPTIONAL_TESTS");
return optionalTests != null &&
asList(optionalTests.split(",")).contains(testClass.getName());
}
}
package org.briarproject.onionwrapper;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.io.File;
import java.util.concurrent.ExecutorService;
import java.util.logging.Logger;
import static java.util.concurrent.Executors.newCachedThreadPool;
import static java.util.concurrent.TimeUnit.MINUTES;
import static java.util.logging.Logger.getLogger;
import static org.briarproject.nullsafety.NullSafety.requireNonNull;
import static org.briarproject.onionwrapper.TestUtils.deleteTestDirectory;
import static org.briarproject.onionwrapper.TestUtils.getArchitectureForTorBinary;
import static org.briarproject.onionwrapper.TestUtils.getTestDirectory;
import static org.briarproject.onionwrapper.TestUtils.isLinux;
import static org.briarproject.onionwrapper.TorWrapper.TorState.CONNECTED;
import static org.junit.Assert.assertTrue;
import static org.junit.Assume.assumeNotNull;
import static org.junit.Assume.assumeTrue;
public class BootstrapTest extends BaseTest {
private final static Logger LOG = getLogger(BootstrapTest.class.getName());
private static final int SOCKS_PORT = 59060;
private static final int CONTROL_PORT = 59061;
private final static long TIMEOUT = MINUTES.toMillis(2);
private final ExecutorService executor = newCachedThreadPool();
private final File torDir = getTestDirectory();
@Before
public void setUp() {
assumeTrue(isLinux());
assumeNotNull(getArchitectureForTorBinary());
}
@After
public void tearDown() {
deleteTestDirectory(torDir);
executor.shutdown();
}
@Test
public void testBootstrapping() throws Exception {
String architecture = requireNonNull(getArchitectureForTorBinary());
TorWrapper tor = new UnixTorWrapper(executor, executor, architecture, torDir,
CONTROL_PORT, SOCKS_PORT);
boolean connected;
try {
tor.start();
tor.enableNetwork(true);
long start = System.currentTimeMillis();
while (System.currentTimeMillis() - start < TIMEOUT) {
if (tor.getTorState() == CONNECTED) break;
//noinspection BusyWait
Thread.sleep(500);
}
connected = tor.getTorState() == CONNECTED;
if (connected) LOG.info("Connected to Tor");
else LOG.warning("Could not connect to Tor within timeout");
} finally {
tor.stop();
}
assertTrue(connected);
}
}
......@@ -33,6 +33,7 @@ import static org.briarproject.onionwrapper.TestUtils.deleteTestDirectory;
import static org.briarproject.onionwrapper.TestUtils.getArchitectureForTorBinary;
import static org.briarproject.onionwrapper.TestUtils.getTestDirectory;
import static org.briarproject.onionwrapper.TestUtils.isLinux;
import static org.briarproject.onionwrapper.TestUtils.isOptionalTestEnabled;
import static org.briarproject.onionwrapper.TorWrapper.TorState.CONNECTED;
import static org.junit.Assert.fail;
import static org.junit.Assume.assumeNotNull;
......@@ -92,6 +93,7 @@ public class BridgeTest extends BaseTest {
@Before
public void setUp() {
assumeTrue(isOptionalTestEnabled(BridgeTest.class));
assumeTrue(isLinux());
assumeNotNull(getArchitectureForTorBinary());
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment