[testng] 102/160: Fix #599 IHookable ignored when a timeout is set

Eugene Zhukov eugene-guest at moszumanska.debian.org
Tue Aug 18 10:22:26 UTC 2015


This is an automated email from the git hooks/post-receive script.

eugene-guest pushed a commit to annotated tag testng-6.9.5
in repository testng.

commit 8e84be5f48c104aa57cd9de8db3dd4d7a676040c
Author: Julien Herr <julien.herr at alcatel-lucent.com>
Date:   Wed Jun 10 01:05:50 2015 +0200

    Fix #599 IHookable ignored when a timeout is set
---
 .../org/testng/internal/InvokeMethodRunnable.java  | 18 ++++++++++---
 src/main/java/org/testng/internal/Invoker.java     | 30 ++++++++--------------
 .../testng/internal/MethodInvocationHelper.java    | 20 ++++++++++-----
 3 files changed, 39 insertions(+), 29 deletions(-)

diff --git a/src/main/java/org/testng/internal/InvokeMethodRunnable.java b/src/main/java/org/testng/internal/InvokeMethodRunnable.java
index 51dde5b..c89a6c0 100644
--- a/src/main/java/org/testng/internal/InvokeMethodRunnable.java
+++ b/src/main/java/org/testng/internal/InvokeMethodRunnable.java
@@ -1,6 +1,8 @@
 package org.testng.internal;
 
+import org.testng.IHookable;
 import org.testng.ITestNGMethod;
+import org.testng.ITestResult;
 
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
@@ -14,14 +16,20 @@ public class InvokeMethodRunnable implements Runnable {
   private ITestNGMethod m_method = null;
   private Object m_instance = null;
   private Object[] m_parameters = null;
+  private final IHookable hookable;
+  private final ITestResult testResult;
 
   public InvokeMethodRunnable(ITestNGMethod thisMethod,
                               Object instance,
-                              Object[] parameters)
+                              Object[] parameters,
+                              IHookable hookable,
+                              ITestResult testResult)
   {
     m_method = thisMethod;
     m_instance = instance;
     m_parameters = parameters;
+    this.hookable = hookable;
+    this.testResult = testResult;
   }
 
   @Override
@@ -43,9 +51,13 @@ public class InvokeMethodRunnable implements Runnable {
       RuntimeException t = null;
       try {
         Method m = m_method.getMethod();
-        MethodInvocationHelper.invokeMethod(m, m_instance, m_parameters);
+        if (hookable == null) {
+          MethodInvocationHelper.invokeMethod(m, m_instance, m_parameters);
+        } else {
+          MethodInvocationHelper.invokeHookable(m_instance, m_parameters, hookable, m, testResult);
+        }
       }
-      catch(InvocationTargetException | IllegalAccessException e) {
+      catch(Throwable e) {
         t = new TestNGRuntimeException(e.getCause());
       }
       if(null != t) {
diff --git a/src/main/java/org/testng/internal/Invoker.java b/src/main/java/org/testng/internal/Invoker.java
index 8678a98..9435cae 100644
--- a/src/main/java/org/testng/internal/Invoker.java
+++ b/src/main/java/org/testng/internal/Invoker.java
@@ -628,34 +628,26 @@ public class Invoker implements IInvoker {
       if(confInvocationPassed(tm, tm, testClass, instance)) {
         log(3, "Invoking " + tm.getRealClass().getName() + "." + tm.getMethodName());
 
-        // If no timeOut, just invoke the method
-        if (MethodHelper.calculateTimeOut(tm) <= 0) {
-          Reporter.setCurrentTestResult(testResult);
-          //
-          // If this method is a IHookable, invoke its run() method
-          //
-          IHookable hookableInstance =
-              IHookable.class.isAssignableFrom(tm.getRealClass()) ?
+        Reporter.setCurrentTestResult(testResult);
+
+        // If this method is a IHookable, invoke its run() method
+        IHookable hookableInstance =
+            IHookable.class.isAssignableFrom(tm.getRealClass()) ?
             (IHookable) instance : m_configuration.getHookable();
+
+        if (MethodHelper.calculateTimeOut(tm) <= 0) {
           if (hookableInstance != null) {
             MethodInvocationHelper.invokeHookable(instance,
                 parameterValues, hookableInstance, thisMethod, testResult);
-          }
-          //
-          // Not a IHookable, invoke directly
-          //
-          else {
+          } else {
+            // Not a IHookable, invoke directly
             MethodInvocationHelper.invokeMethod(thisMethod, instance,
                 parameterValues);
           }
           testResult.setStatus(ITestResult.SUCCESS);
-        }
-        else {
-          //
+        } else {
           // Method with a timeout
-          //
-          Reporter.setCurrentTestResult(testResult);
-          MethodInvocationHelper.invokeWithTimeout(tm, instance, parameterValues, testResult);
+          MethodInvocationHelper.invokeWithTimeout(tm, instance, parameterValues, testResult, hookableInstance);
         }
       }
       else {
diff --git a/src/main/java/org/testng/internal/MethodInvocationHelper.java b/src/main/java/org/testng/internal/MethodInvocationHelper.java
index 8720d23..7bff43f 100644
--- a/src/main/java/org/testng/internal/MethodInvocationHelper.java
+++ b/src/main/java/org/testng/internal/MethodInvocationHelper.java
@@ -186,7 +186,7 @@ public class MethodInvocationHelper {
    */
   protected static void invokeHookable(final Object testInstance, final Object[] parameters,
                                        final IHookable hookable, final Method thisMethod,
-                                       final TestResult testResult) throws Throwable {
+                                       final ITestResult testResult) throws Throwable {
     final Throwable[] error = new Throwable[1];
 
     IHookCallBack callback = new IHookCallBack() {
@@ -219,19 +219,25 @@ public class MethodInvocationHelper {
   protected static void invokeWithTimeout(ITestNGMethod tm, Object instance,
       Object[] parameterValues, ITestResult testResult)
       throws InterruptedException, ThreadExecutionException {
+    invokeWithTimeout(tm, instance, parameterValues, testResult, null);
+  }
+
+  protected static void invokeWithTimeout(ITestNGMethod tm, Object instance,
+      Object[] parameterValues, ITestResult testResult, IHookable hookable)
+      throws InterruptedException, ThreadExecutionException {
     if (ThreadUtil.isTestNGThread()) {
       // We are already running in our own executor, don't create another one (or we will
       // lose the time out of the enclosing executor).
-      invokeWithTimeoutWithNoExecutor(tm, instance, parameterValues, testResult);
+      invokeWithTimeoutWithNoExecutor(tm, instance, parameterValues, testResult, hookable);
     } else {
-      invokeWithTimeoutWithNewExecutor(tm, instance, parameterValues, testResult);
+      invokeWithTimeoutWithNewExecutor(tm, instance, parameterValues, testResult, hookable);
     }
   }
 
   private static void invokeWithTimeoutWithNoExecutor(ITestNGMethod tm, Object instance,
-      Object[] parameterValues, ITestResult testResult) {
+      Object[] parameterValues, ITestResult testResult, IHookable hookable) {
 
-    InvokeMethodRunnable imr = new InvokeMethodRunnable(tm, instance, parameterValues);
+    InvokeMethodRunnable imr = new InvokeMethodRunnable(tm, instance, parameterValues, hookable, testResult);
     try {
       imr.run();
       testResult.setStatus(ITestResult.SUCCESS);
@@ -242,11 +248,11 @@ public class MethodInvocationHelper {
   }
 
   private static void invokeWithTimeoutWithNewExecutor(ITestNGMethod tm, Object instance,
-      Object[] parameterValues, ITestResult testResult)
+      Object[] parameterValues, ITestResult testResult, IHookable hookable)
       throws InterruptedException, ThreadExecutionException {
     IExecutor exec = ThreadUtil.createExecutor(1, tm.getMethodName());
 
-    InvokeMethodRunnable imr = new InvokeMethodRunnable(tm, instance, parameterValues);
+    InvokeMethodRunnable imr = new InvokeMethodRunnable(tm, instance, parameterValues, hookable, testResult);
     IFutureResult future = exec.submitRunnable(imr);
     exec.shutdown();
     long realTimeOut = MethodHelper.calculateTimeOut(tm);

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/testng.git



More information about the pkg-java-commits mailing list