jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r1782600 - /jmeter/trunk/test/src/org/apache/jmeter/samplers/TestSampleResult.java
Date Sat, 11 Feb 2017 13:06:33 GMT
Author: sebb
Date: Sat Feb 11 13:06:32 2017
New Revision: 1782600

URL: http://svn.apache.org/viewvc?rev=1782600&view=rev
Log:
Allow for sleeps that take longer than expected

Modified:
    jmeter/trunk/test/src/org/apache/jmeter/samplers/TestSampleResult.java

Modified: jmeter/trunk/test/src/org/apache/jmeter/samplers/TestSampleResult.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/test/src/org/apache/jmeter/samplers/TestSampleResult.java?rev=1782600&r1=1782599&r2=1782600&view=diff
==============================================================================
--- jmeter/trunk/test/src/org/apache/jmeter/samplers/TestSampleResult.java (original)
+++ jmeter/trunk/test/src/org/apache/jmeter/samplers/TestSampleResult.java Sat Feb 11 13:06:32
2017
@@ -67,19 +67,17 @@ public class TestSampleResult {
             SampleResult res = new SampleResult(false);
             // Check sample increments OK
             res.sampleStart();
-            Thread.sleep(100);
+            long totalSampleTime = sleep(100); // accumulate the time spent 'sampling'
             res.samplePause();
 
-            Thread.sleep(200);
+            Thread.sleep(200); // This should be ignored 
 
             // Re-increment
             res.sampleResume();
-            Thread.sleep(100);
+            totalSampleTime += sleep(100);
             res.sampleEnd();
             long sampleTime = res.getTime();
-            if ((sampleTime < 180) || (sampleTime > 290)) {
-                fail("Accumulated time (" + sampleTime + ") was not between 180 and 290 ms");
-            }
+            assertEquals("Accumulated sample time", totalSampleTime, sampleTime, 50);
         }
 
         @Test
@@ -87,19 +85,17 @@ public class TestSampleResult {
             SampleResult res = new SampleResult(true);
             // Check sample increments OK
             res.sampleStart();
-            Thread.sleep(100);
+            long totalSampleTime = sleep(100); // accumulate the time spent 'sampling'
             res.samplePause();
 
-            Thread.sleep(200);
+            Thread.sleep(200); // this should be ignored
 
             // Re-increment
             res.sampleResume();
-            Thread.sleep(100);
+            totalSampleTime += sleep(100);
             res.sampleEnd();
             long sampleTime = res.getTime();
-            if ((sampleTime < 180) || (sampleTime > 290)) {
-                fail("Accumulated time (" + sampleTime + ") was not between 180 and 290 ms");
-            }
+            assertEquals("Accumulated sample time", totalSampleTime, sampleTime, 50);
         }
 
         private LogRecordingDelegatingLogger recordLogger;
@@ -341,5 +337,13 @@ public class TestSampleResult {
             assertEquals("aBCd",res.getDataEncodingNoDefault());
             assertEquals("text",res.getDataType());         
         }
+
+        // sleep and return how long we actually slept
+        // may be rather longer if the system is busy
+        private long sleep(long ms) throws InterruptedException {
+            long start = System.currentTimeMillis();
+            Thread.sleep(ms);
+            return System.currentTimeMillis() - start;
+        }
 }
 



Mime
View raw message