mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 11:19:04 +01:00
Increased some timeouts and added latches to stop tests failing under
heavy load.
This commit is contained in:
@@ -20,7 +20,7 @@ public class LockFairnessTest extends BriarTestCase {
|
||||
Thread shortReader = new ReaderThread(lock, 1);
|
||||
// The short-running reader should complete before the long-running one
|
||||
longReader.start();
|
||||
Thread.sleep(1);
|
||||
Thread.sleep(10);
|
||||
shortReader.start();
|
||||
// Wait for the long-running reader to finish (it should finish last)
|
||||
longReader.join();
|
||||
@@ -40,9 +40,9 @@ public class LockFairnessTest extends BriarTestCase {
|
||||
// The short-running reader should not overtake the writer and share
|
||||
// the lock with the long-running reader
|
||||
longReader.start();
|
||||
Thread.sleep(1);
|
||||
Thread.sleep(10);
|
||||
writer.start();
|
||||
Thread.sleep(1);
|
||||
Thread.sleep(10);
|
||||
shortReader.start();
|
||||
// Wait for the short-running reader to finish (it should finish last)
|
||||
shortReader.join();
|
||||
|
||||
@@ -945,7 +945,8 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
|
||||
@Test
|
||||
public void testCloseWaitsForCommit() throws Exception {
|
||||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
final CountDownLatch closing = new CountDownLatch(1);
|
||||
final CountDownLatch closed = new CountDownLatch(1);
|
||||
final AtomicBoolean transactionFinished = new AtomicBoolean(false);
|
||||
final AtomicBoolean error = new AtomicBoolean(false);
|
||||
final Database<Connection> db = open(false);
|
||||
@@ -953,32 +954,35 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
// Start a transaction
|
||||
Connection txn = db.startTransaction();
|
||||
// In another thread, close the database
|
||||
Thread t = new Thread() {
|
||||
Thread close = new Thread() {
|
||||
public void run() {
|
||||
try {
|
||||
closing.countDown();
|
||||
db.close();
|
||||
if(!transactionFinished.get()) error.set(true);
|
||||
latch.countDown();
|
||||
closed.countDown();
|
||||
} catch(Exception e) {
|
||||
error.set(true);
|
||||
}
|
||||
}
|
||||
};
|
||||
t.start();
|
||||
close.start();
|
||||
closing.await();
|
||||
// Do whatever the transaction needs to do
|
||||
Thread.sleep(10);
|
||||
transactionFinished.set(true);
|
||||
// Commit the transaction
|
||||
db.commitTransaction(txn);
|
||||
// The other thread should now terminate
|
||||
assertTrue(latch.await(5, TimeUnit.SECONDS));
|
||||
assertTrue(closed.await(5, TimeUnit.SECONDS));
|
||||
// Check that the other thread didn't encounter an error
|
||||
assertFalse(error.get());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCloseWaitsForAbort() throws Exception {
|
||||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
final CountDownLatch closing = new CountDownLatch(1);
|
||||
final CountDownLatch closed = new CountDownLatch(1);
|
||||
final AtomicBoolean transactionFinished = new AtomicBoolean(false);
|
||||
final AtomicBoolean error = new AtomicBoolean(false);
|
||||
final Database<Connection> db = open(false);
|
||||
@@ -986,25 +990,27 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
// Start a transaction
|
||||
Connection txn = db.startTransaction();
|
||||
// In another thread, close the database
|
||||
Thread t = new Thread() {
|
||||
Thread close = new Thread() {
|
||||
public void run() {
|
||||
try {
|
||||
closing.countDown();
|
||||
db.close();
|
||||
if(!transactionFinished.get()) error.set(true);
|
||||
latch.countDown();
|
||||
closed.countDown();
|
||||
} catch(Exception e) {
|
||||
error.set(true);
|
||||
}
|
||||
}
|
||||
};
|
||||
t.start();
|
||||
close.start();
|
||||
closing.await();
|
||||
// Do whatever the transaction needs to do
|
||||
Thread.sleep(10);
|
||||
transactionFinished.set(true);
|
||||
// Abort the transaction
|
||||
db.abortTransaction(txn);
|
||||
// The other thread should now terminate
|
||||
assertTrue(latch.await(5, TimeUnit.SECONDS));
|
||||
assertTrue(closed.await(5, TimeUnit.SECONDS));
|
||||
// Check that the other thread didn't encounter an error
|
||||
assertFalse(error.get());
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ public class PollingRemovableDriveMonitorTest extends BriarTestCase {
|
||||
fail();
|
||||
}
|
||||
});
|
||||
Thread.sleep(50);
|
||||
Thread.sleep(100);
|
||||
// The monitor should rethrow the exception when it stops
|
||||
try {
|
||||
monitor.stop();
|
||||
|
||||
@@ -47,12 +47,12 @@ public class SimpleSocketPluginTest extends BriarTestCase {
|
||||
Socket s = new Socket();
|
||||
assertEquals(0, callback.incomingConnections);
|
||||
s.connect(addr, 100);
|
||||
Thread.sleep(100);
|
||||
Thread.sleep(200);
|
||||
assertEquals(1, callback.incomingConnections);
|
||||
s.close();
|
||||
// Stop the plugin
|
||||
plugin.stop();
|
||||
Thread.sleep(100);
|
||||
Thread.sleep(200);
|
||||
// The plugin should no longer be listening
|
||||
try {
|
||||
s = new Socket();
|
||||
|
||||
Reference in New Issue
Block a user