You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jmeter.apache.org by fs...@apache.org on 2019/08/17 10:29:28 UTC

[jmeter] 04/04: Invert logic from checking for success to checking for failure

This is an automated email from the ASF dual-hosted git repository.

fschumacher pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jmeter.git

commit bdd6dd63088b6de2f615edca49894dd5773a0763
Author: Felix Schumacher <fe...@internetallee.de>
AuthorDate: Sat Aug 17 12:09:20 2019 +0200

    Invert logic from checking for success to checking for failure
    
    Closes #479 on github
---
 .../apache/jmeter/assertions/CompareAssertion.java | 33 +++++++++-------------
 xdocs/changes.xml                                  |  2 ++
 2 files changed, 16 insertions(+), 19 deletions(-)

diff --git a/src/components/src/main/java/org/apache/jmeter/assertions/CompareAssertion.java b/src/components/src/main/java/org/apache/jmeter/assertions/CompareAssertion.java
index 6609901..a027645 100644
--- a/src/components/src/main/java/org/apache/jmeter/assertions/CompareAssertion.java
+++ b/src/components/src/main/java/org/apache/jmeter/assertions/CompareAssertion.java
@@ -70,20 +70,17 @@ public class CompareAssertion extends AbstractTestElement implements Assertion,
         }
         long prevTime = -1;
         SampleResult prevResult = null;
-        boolean success = true;
         for (SampleResult currentResult : responses) {
             long currentTime = currentResult.getTime();
             if (prevTime != -1) {
-                success = Math.abs(prevTime - currentTime) <= compareTime;
-                prevResult = currentResult;
+                boolean failure = Math.abs(prevTime - currentTime) > compareTime;
+                if (failure) {
+                    markTimeFailure(result, prevResult, prevTime, currentResult, currentTime);
+                    return;
+                }
             }
-            if (success) {
-                prevResult = currentResult;
-                prevTime = currentTime;
-                continue;
-            }
-            markTimeFailure(result, prevResult, prevTime, currentResult, currentTime);
-            return;
+            prevResult = currentResult;
+            prevTime = currentTime;
         }
     }
 
@@ -110,20 +107,18 @@ public class CompareAssertion extends AbstractTestElement implements Assertion,
         }
         String prevContent = null;
         SampleResult prevResult = null;
-        boolean success = true;
         for (SampleResult currentResult : responses) {
             String currentContent = currentResult.getResponseDataAsString();
             currentContent = filterString(currentContent);
             if (prevContent != null) {
-                success = prevContent.equals(currentContent);
+                boolean failure = !prevContent.equals(currentContent);
+                if (failure) {
+                    markContentFailure(result, prevContent, prevResult, currentResult, currentContent);
+                    return;
+                }
             }
-            if (success) {
-                prevResult = currentResult;
-                prevContent = currentContent;
-                continue;
-            }
-            markContentFailure(result, prevContent, prevResult, currentResult, currentContent);
-            return;
+            prevResult = currentResult;
+            prevContent = currentContent;
         }
     }
 
diff --git a/xdocs/changes.xml b/xdocs/changes.xml
index 7cd7953..a94edca 100644
--- a/xdocs/changes.xml
+++ b/xdocs/changes.xml
@@ -139,6 +139,7 @@ to view the last release notes of version 5.1.1.
     <li>Updated jackson-annotations, jackson-core and jackson-databind to 2.9.9/2.9.9.3 (from 2.9.8)</li>
     <li><bug>63529</bug>Add more unit tests for org.apache.jorphan.util.JOrphanUtils. Contributed by John Bergqvist(John.Bergqvist at diffblue.com)</li>
     <li>Updated to latest checkstyle (version 8.22)</li>
+    <li>Clean-up of code in <code>CompareAssertion</code> and other locations. Based on patch by Graham Russell (graham at ham1.co.uk)</li>
 </ul>
 
  <!-- =================== Bug fixes =================== -->
@@ -219,6 +220,7 @@ to view the last release notes of version 5.1.1.
   <li>Sun Tao (buzzerrookie at hotmail.com)</li>
   <li>John Bergqvist (John.Bergqvist at diffblue.com)</li>
   <li>Franz Schwab (franz.schwab@exasol.com)</li>
+  <li>Graham Russell (graham at ham1.co.uk)</li>
 </ul>
 <p>We also thank bug reporters who helped us improve JMeter.</p>
 <ul>