From 2ce8d2a418e06e27e04f1eefb2eabb064beaac54 Mon Sep 17 00:00:00 2001 From: akwizgran <akwizgran@users.sourceforge.net> Date: Wed, 5 Oct 2011 14:09:43 +0100 Subject: [PATCH] Fixed a race condition: start the monitor before creating files. --- test/build.xml | 1 + .../briar/plugins/file/UnixRemovableDriveMonitorTest.java | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/test/build.xml b/test/build.xml index 84cbbdfff1..284ead0fec 100644 --- a/test/build.xml +++ b/test/build.xml @@ -13,6 +13,7 @@ <path refid='test-classes'/> <path refid='util-classes'/> </classpath> + <jvmarg value='-Djava.library.path=../lib'/> <test name='net.sf.briar.LockFairnessTest'/> <test name='net.sf.briar.ProtocolIntegrationTest'/> <test name='net.sf.briar.crypto.CounterModeTest'/> diff --git a/test/net/sf/briar/plugins/file/UnixRemovableDriveMonitorTest.java b/test/net/sf/briar/plugins/file/UnixRemovableDriveMonitorTest.java index b4294b1adc..2c2dd6047a 100644 --- a/test/net/sf/briar/plugins/file/UnixRemovableDriveMonitorTest.java +++ b/test/net/sf/briar/plugins/file/UnixRemovableDriveMonitorTest.java @@ -36,15 +36,14 @@ public class UnixRemovableDriveMonitorTest extends TestCase { final CountDownLatch latch = new CountDownLatch(1); final List<File> detected = new ArrayList<File>(); // Create a monitor that will wait for two files before stopping + final RemovableDriveMonitor monitor = createMonitor(testDir); + monitor.start(); new Thread() { @Override public void run() { try { - RemovableDriveMonitor monitor = createMonitor(testDir); - monitor.start(); detected.add(monitor.waitForInsertion()); detected.add(monitor.waitForInsertion()); - monitor.stop(); latch.countDown(); } catch(IOException e) { fail(); @@ -57,7 +56,8 @@ public class UnixRemovableDriveMonitorTest extends TestCase { assertTrue(file1.createNewFile()); assertTrue(file2.createNewFile()); // Wait for the monitor to detect the files - latch.await(1, TimeUnit.SECONDS); + assertTrue(latch.await(2, TimeUnit.SECONDS)); + monitor.stop(); // Check that both files were detected assertEquals(2, detected.size()); assertTrue(detected.contains(file1)); -- GitLab