diff --git a/core/src/test/java/hudson/FilePathTest.java b/core/src/test/java/hudson/FilePathTest.java index 69551125e2784f835a62eaffdd44989e52f0e1ff..28a03acca7f91288f0c31d12e7471b5a82e1f6ac 100644 --- a/core/src/test/java/hudson/FilePathTest.java +++ b/core/src/test/java/hudson/FilePathTest.java @@ -66,7 +66,7 @@ public class FilePathTest extends ChannelTestCase { * An attempt to reproduce the file descriptor leak. * If this operation leaks a file descriptor, 2500 should be enough, I think. */ - public void testCopyTo2() throws Exception { + public void testNoFileLeakInCopyTo() throws Exception { for (int j=0; j<2500; j++) { File tmp = File.createTempFile("testCopyFrom",""); FilePath f = new FilePath(tmp); @@ -93,23 +93,19 @@ public class FilePathTest extends ChannelTestCase { * Also see JENKINS-7897 */ @Bug(7871) - public void testCopyTo3() throws Exception { + public void testNoRaceConditionInCopyTo() throws Exception { final File tmp = File.createTempFile("testCopyTo3",""); - FileOutputStream os = new FileOutputStream(tmp); final int size = 90000; - byte[] buf = new byte[size]; - for (int i=0; i> r = new ArrayList>(); + List> r = new ArrayList>(); for (int i=0; i<100; i++) { - r.add(es.submit(new Callable() { - public Object call() throws Exception { + r.add(es.submit(new Callable() { + public Void call() throws Exception { class Sink extends OutputStream { private Exception closed; private volatile int count; @@ -154,14 +150,22 @@ public class FilePathTest extends ChannelTestCase { })); } - for (java.util.concurrent.Future f : r) + for (java.util.concurrent.Future f : r) f.get(); } finally { es.shutdown(); + tmp.delete(); } } - + private void givenSomeContentInFile(File file, int size) throws IOException { + FileOutputStream os = new FileOutputStream(file); + byte[] buf = new byte[size]; + for (int i=0; ilocal copy used to return 0 if all files were "up to date"