mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-15 12:19:54 +01:00
Replaced sleep with a latch to prevent test failures under heavy load.
This commit is contained in:
@@ -34,7 +34,7 @@ public class SimpleSocketPluginTest extends BriarTestCase {
|
|||||||
SimpleSocketPlugin plugin = new SimpleSocketPlugin(e, callback, 0L);
|
SimpleSocketPlugin plugin = new SimpleSocketPlugin(e, callback, 0L);
|
||||||
plugin.start();
|
plugin.start();
|
||||||
// The plugin should have bound a socket and stored the port number
|
// The plugin should have bound a socket and stored the port number
|
||||||
callback.latch.await(5, TimeUnit.SECONDS);
|
assertTrue(callback.propertiesLatch.await(5, TimeUnit.SECONDS));
|
||||||
String host = callback.local.get("internal");
|
String host = callback.local.get("internal");
|
||||||
assertNotNull(host);
|
assertNotNull(host);
|
||||||
assertEquals("127.0.0.1", host);
|
assertEquals("127.0.0.1", host);
|
||||||
@@ -45,14 +45,11 @@ public class SimpleSocketPluginTest extends BriarTestCase {
|
|||||||
// The plugin should be listening on the port
|
// The plugin should be listening on the port
|
||||||
InetSocketAddress addr = new InetSocketAddress(host, port);
|
InetSocketAddress addr = new InetSocketAddress(host, port);
|
||||||
Socket s = new Socket();
|
Socket s = new Socket();
|
||||||
assertEquals(0, callback.incomingConnections);
|
|
||||||
s.connect(addr, 100);
|
s.connect(addr, 100);
|
||||||
Thread.sleep(200);
|
assertTrue(callback.connectionsLatch.await(5, TimeUnit.SECONDS));
|
||||||
assertEquals(1, callback.incomingConnections);
|
|
||||||
s.close();
|
s.close();
|
||||||
// Stop the plugin
|
// Stop the plugin
|
||||||
plugin.stop();
|
plugin.stop();
|
||||||
Thread.sleep(200);
|
|
||||||
// The plugin should no longer be listening
|
// The plugin should no longer be listening
|
||||||
try {
|
try {
|
||||||
s = new Socket();
|
s = new Socket();
|
||||||
@@ -105,13 +102,12 @@ public class SimpleSocketPluginTest extends BriarTestCase {
|
|||||||
|
|
||||||
private final Map<ContactId, TransportProperties> remote =
|
private final Map<ContactId, TransportProperties> remote =
|
||||||
new Hashtable<ContactId, TransportProperties>();
|
new Hashtable<ContactId, TransportProperties>();
|
||||||
private final CountDownLatch latch = new CountDownLatch(1);
|
private final CountDownLatch propertiesLatch = new CountDownLatch(1);
|
||||||
|
private final CountDownLatch connectionsLatch = new CountDownLatch(1);
|
||||||
|
|
||||||
private TransportConfig config = new TransportConfig();
|
private TransportConfig config = new TransportConfig();
|
||||||
private TransportProperties local = new TransportProperties();
|
private TransportProperties local = new TransportProperties();
|
||||||
|
|
||||||
private int incomingConnections = 0;
|
|
||||||
|
|
||||||
public TransportConfig getConfig() {
|
public TransportConfig getConfig() {
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
@@ -129,8 +125,8 @@ public class SimpleSocketPluginTest extends BriarTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setLocalProperties(TransportProperties p) {
|
public void setLocalProperties(TransportProperties p) {
|
||||||
latch.countDown();
|
|
||||||
local = p;
|
local = p;
|
||||||
|
propertiesLatch.countDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int showChoice(String[] options, String... message) {
|
public int showChoice(String[] options, String... message) {
|
||||||
@@ -144,7 +140,7 @@ public class SimpleSocketPluginTest extends BriarTestCase {
|
|||||||
public void showMessage(String... message) {}
|
public void showMessage(String... message) {}
|
||||||
|
|
||||||
public void incomingConnectionCreated(DuplexTransportConnection d) {
|
public void incomingConnectionCreated(DuplexTransportConnection d) {
|
||||||
incomingConnections++;
|
connectionsLatch.countDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void outgoingConnectionCreated(ContactId c,
|
public void outgoingConnectionCreated(ContactId c,
|
||||||
|
|||||||
Reference in New Issue
Block a user