From d78081b57d4a10a96f4317cc5fc2074868914d5c Mon Sep 17 00:00:00 2001 From: akwizgran <akwizgran@users.sourceforge.net> Date: Wed, 28 Mar 2012 23:30:45 +0100 Subject: [PATCH] Increased some timeouts and added latches to stop tests failing under heavy load. --- test/net/sf/briar/LockFairnessTest.java | 6 ++--- test/net/sf/briar/db/H2DatabaseTest.java | 26 ++++++++++++------- .../PollingRemovableDriveMonitorTest.java | 2 +- .../socket/SimpleSocketPluginTest.java | 4 +-- 4 files changed, 22 insertions(+), 16 deletions(-) diff --git a/test/net/sf/briar/LockFairnessTest.java b/test/net/sf/briar/LockFairnessTest.java index 7a798d40d9..7686d4bd11 100644 --- a/test/net/sf/briar/LockFairnessTest.java +++ b/test/net/sf/briar/LockFairnessTest.java @@ -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(); diff --git a/test/net/sf/briar/db/H2DatabaseTest.java b/test/net/sf/briar/db/H2DatabaseTest.java index d171e56cdf..cbc223c06f 100644 --- a/test/net/sf/briar/db/H2DatabaseTest.java +++ b/test/net/sf/briar/db/H2DatabaseTest.java @@ -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()); } diff --git a/test/net/sf/briar/plugins/file/PollingRemovableDriveMonitorTest.java b/test/net/sf/briar/plugins/file/PollingRemovableDriveMonitorTest.java index f3659ea3ad..f2d7a65dfc 100644 --- a/test/net/sf/briar/plugins/file/PollingRemovableDriveMonitorTest.java +++ b/test/net/sf/briar/plugins/file/PollingRemovableDriveMonitorTest.java @@ -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(); diff --git a/test/net/sf/briar/plugins/socket/SimpleSocketPluginTest.java b/test/net/sf/briar/plugins/socket/SimpleSocketPluginTest.java index cf4cb3fca9..23e6381103 100644 --- a/test/net/sf/briar/plugins/socket/SimpleSocketPluginTest.java +++ b/test/net/sf/briar/plugins/socket/SimpleSocketPluginTest.java @@ -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(); -- GitLab