killbill-memoizeit

test: harden AbortAfterFirstFailureListener Signed-off-by:

4/13/2018 9:32:46 AM

Details

diff --git a/entitlement/src/test/java/org/killbill/billing/entitlement/api/TestEntitlementDateHelper.java b/entitlement/src/test/java/org/killbill/billing/entitlement/api/TestEntitlementDateHelper.java
index d53c82d..1f9e1b8 100644
--- a/entitlement/src/test/java/org/killbill/billing/entitlement/api/TestEntitlementDateHelper.java
+++ b/entitlement/src/test/java/org/killbill/billing/entitlement/api/TestEntitlementDateHelper.java
@@ -31,6 +31,7 @@ import org.killbill.billing.entitlement.EntitlementTestSuiteNoDB;
 import org.killbill.billing.mock.MockAccountBuilder;
 import org.testng.Assert;
 import org.testng.annotations.BeforeClass;
+import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
 import static org.testng.Assert.assertTrue;
@@ -39,9 +40,9 @@ public class TestEntitlementDateHelper extends EntitlementTestSuiteNoDB {
 
     private EntitlementDateHelper dateHelper;
 
-    @BeforeClass(groups = "fast")
+    @BeforeMethod(groups = "fast")
     public void beforeMethod() throws Exception {
-        super.beforeClass();
+        super.beforeMethod();
 
         dateHelper = new EntitlementDateHelper();
         clock.resetDeltaFromReality();
diff --git a/util/src/test/java/org/killbill/billing/api/AbortAfterFirstFailureListener.java b/util/src/test/java/org/killbill/billing/api/AbortAfterFirstFailureListener.java
index 09e26ab..69c1600 100644
--- a/util/src/test/java/org/killbill/billing/api/AbortAfterFirstFailureListener.java
+++ b/util/src/test/java/org/killbill/billing/api/AbortAfterFirstFailureListener.java
@@ -17,6 +17,8 @@
 
 package org.killbill.billing.api;
 
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.testng.IInvokedMethod;
 import org.testng.IInvokedMethodListener;
 import org.testng.ITestResult;
@@ -24,7 +26,9 @@ import org.testng.SkipException;
 
 public class AbortAfterFirstFailureListener implements IInvokedMethodListener {
 
-    private boolean hasFailures = false;
+    private static final Logger logger = LoggerFactory.getLogger(AbortAfterFirstFailureListener.class);
+
+    private static boolean hasFailures = false;
 
     @Override
     public void beforeInvocation(final IInvokedMethod method, final ITestResult testResult) {
@@ -45,10 +49,15 @@ public class AbortAfterFirstFailureListener implements IInvokedMethodListener {
             return;
         }
 
-        if (!testResult.isSuccess()) {
+        if (testResult.getStatus() == ITestResult.FAILURE) {
             synchronized (this) {
+                logger.warn("!!! Test failure, all other tests will be skipped: {} !!!", testResult);
                 hasFailures = true;
             }
         }
     }
+
+    public static boolean hasFailures() {
+        return hasFailures;
+    }
 }
diff --git a/util/src/test/java/org/killbill/billing/GuicyKillbillTestSuite.java b/util/src/test/java/org/killbill/billing/GuicyKillbillTestSuite.java
index 331ce03..a62c774 100644
--- a/util/src/test/java/org/killbill/billing/GuicyKillbillTestSuite.java
+++ b/util/src/test/java/org/killbill/billing/GuicyKillbillTestSuite.java
@@ -135,6 +135,10 @@ public class GuicyKillbillTestSuite implements IHookable {
 
     @BeforeMethod(alwaysRun = true)
     public void beforeMethodAlwaysRun(final Method method) throws Exception {
+        if (AbortAfterFirstFailureListener.hasFailures()) {
+            return;
+        }
+
         log.info("***************************************************************************************************");
         log.info("*** Starting test {}:{}", method.getDeclaringClass().getName(), method.getName());
         log.info("***************************************************************************************************");
@@ -146,6 +150,10 @@ public class GuicyKillbillTestSuite implements IHookable {
 
     @AfterMethod(alwaysRun = true)
     public void afterMethodAlwaysRun(final Method method, final ITestResult result) throws Exception {
+        if (AbortAfterFirstFailureListener.hasFailures()) {
+            return;
+        }
+
         final String tag;
         switch (result.getStatus()) {
             case SUCCESS:
diff --git a/util/src/test/java/org/killbill/billing/util/audit/api/TestDefaultAuditUserApi.java b/util/src/test/java/org/killbill/billing/util/audit/api/TestDefaultAuditUserApi.java
index 66129af..76405d9 100644
--- a/util/src/test/java/org/killbill/billing/util/audit/api/TestDefaultAuditUserApi.java
+++ b/util/src/test/java/org/killbill/billing/util/audit/api/TestDefaultAuditUserApi.java
@@ -21,6 +21,7 @@ import java.util.UUID;
 
 import org.testng.Assert;
 import org.testng.annotations.BeforeClass;
+import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
 import org.killbill.billing.ObjectType;
@@ -37,10 +38,8 @@ public class TestDefaultAuditUserApi extends AuditLogsTestBase {
     private List<AuditLog> auditLogs;
     private List<UUID> objectIds;
 
-    @Override
-    @BeforeClass(groups = "fast")
-    public void beforeClass() throws Exception {
-        super.beforeClass();
+    @BeforeMethod(groups = "fast")
+    public void setup() throws Exception {
         auditLogs = ImmutableList.<AuditLog>of(createAuditLog(), createAuditLog(), createAuditLog(), createAuditLog());
         objectIds = ImmutableList.<UUID>of(UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID());