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