From 8a0e13813f65aa7fc2dea976125b3140417b40f4 Mon Sep 17 00:00:00 2001 From: Christoph Kutzinski Date: Sun, 26 Aug 2012 23:26:47 +0200 Subject: [PATCH] minor test refactoring --- core/src/test/java/hudson/FilePathTest.java | 30 ++++++++++++--------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/core/src/test/java/hudson/FilePathTest.java b/core/src/test/java/hudson/FilePathTest.java index 69551125e2..28a03acca7 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" -- GitLab