CVS: junit/src/org/junit/internal/runners MethodRoadie.java, 1.2, 1.3

David Saff <[email protected]> Mon, 02 Jul 2007 13:59:59 -0700
Newsgroups gmane.comp.java.junit.devel
Message-ID <[email protected]>
Update of /cvsroot/junit/junit/src/org/junit/internal/runners
In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv512/src/org/junit/internal/runners

Modified Files:
	MethodRoadie.java 
Log Message:
Fixed bug 1745048: @After method not called after my test timeout in 4.3.1

Index: MethodRoadie.java
===================================================================
RCS file: /cvsroot/junit/junit/src/org/junit/internal/runners/MethodRoadie.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- MethodRoadie.java	2 Jul 2007 18:10:58 -0000	1.2
+++ MethodRoadie.java	2 Jul 2007 20:59:57 -0000	1.3
@@ -46,29 +46,37 @@
 	}
 
 	private void runWithTimeout(long timeout) {
-		ExecutorService service= Executors.newSingleThreadExecutor();
-		Callable<Object> callable= new Callable<Object>() {
-			public Object call() throws Exception {
-				runTest();
-				return null;
-			}
-		};
-		Future<Object> result= service.submit(callable);
-		service.shutdown();
 		try {
-			boolean terminated= service.awaitTermination(timeout,
-					TimeUnit.MILLISECONDS);
-			if (!terminated)
-				service.shutdownNow();
-			result.get(0, TimeUnit.MILLISECONDS); // throws the exception if one occurred during the invocation
-		} catch (TimeoutException e) {
-			addFailure(new Exception(String.format("test timed out after %d milliseconds", timeout)));
-		} catch (Exception e) {
-			addFailure(e);
-		}		
+			runBefores();
+			ExecutorService service= Executors.newSingleThreadExecutor();
+			Callable<Object> callable= new Callable<Object>() {
+				public Object call() throws Exception {
+					runTestMethod();
+					return null;
+				}
+			};
+			Future<Object> result= service.submit(callable);
+			service.shutdown();
+			try {
+				boolean terminated= service.awaitTermination(timeout,
+						TimeUnit.MILLISECONDS);
+				if (!terminated)
+					service.shutdownNow();
+				result.get(0, TimeUnit.MILLISECONDS); // throws the exception if one occurred during the invocation
+			} catch (TimeoutException e) {
+				addFailure(new Exception(String.format("test timed out after %d milliseconds", timeout)));
+			} catch (Exception e) {
+				addFailure(e);
+			}		
+		} catch (FailedBefore e) {
+		} finally {
+			runAfters();
+		}
 	}
 	
 	public void runTest() {
+		// TODO (Jul 2, 2007 4:54:13 PM):  duplicated in timeout branch?
+
 		try {
 			runBefores();
 			runTestMethod();


-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/