Author: lfryc(a)redhat.com
Date: 2010-07-10 17:12:49 -0400 (Sat, 10 Jul 2010)
New Revision: 17910
Modified:
root/tests/metamer/trunk/ftest/test-source/src/main/java/org/richfaces/tests/testapp/a4jPoll/PollTestCase.java
Log:
improved PollTestCase to be more stable - obtaining the run time as time of the arrival of
reponse to client
Modified:
root/tests/metamer/trunk/ftest/test-source/src/main/java/org/richfaces/tests/testapp/a4jPoll/PollTestCase.java
===================================================================
---
root/tests/metamer/trunk/ftest/test-source/src/main/java/org/richfaces/tests/testapp/a4jPoll/PollTestCase.java 2010-07-10
21:12:23 UTC (rev 17909)
+++
root/tests/metamer/trunk/ftest/test-source/src/main/java/org/richfaces/tests/testapp/a4jPoll/PollTestCase.java 2010-07-10
21:12:49 UTC (rev 17910)
@@ -24,6 +24,8 @@
import java.net.URL;
import org.jboss.test.selenium.dom.Event;
+import org.jboss.test.selenium.locator.Attribute;
+import org.jboss.test.selenium.locator.AttributeLocator;
import org.jboss.test.selenium.locator.ElementLocator;
import org.jboss.test.selenium.locator.JQueryLocator;
import org.richfaces.tests.testapp.AbstractTestappTestCase;
@@ -35,6 +37,7 @@
import static org.testng.Assert.*;
import static org.jboss.test.selenium.SystemProperties.isSeleniumDebug;
import static org.jboss.test.selenium.utils.text.SimplifiedFormat.format;
+import static org.jboss.test.selenium.utils.PrimitiveUtils.*;
/**
* Tests the a4j:poll component.
@@ -44,14 +47,16 @@
*/
public class PollTestCase extends AbstractTestappTestCase {
+ private static final Attribute ATTRIBUTE_TITLE = new Attribute("title");
private static final int[] TEST_INTERVAL_VALUES = new int[]{1000, 5000, 500};
private static final int TEST_INTERVAL_ITERATIONS = 5;
- private static final int MAX_DEVIATION = 250;
- private static final int MAX_AVERAGE_DEVIATION = 100;
+ private static final int MAX_DEVIATION = 100;
+ private static final int MAX_AVERAGE_DEVIATION = 50;
ElementLocator attributeEnabled = id("form:attributes:enabledInput");
ElementLocator attributeInterval = id("form:attributes:intervalInput");
JQueryLocator time = pjq("span[id$=time]");
+ AttributeLocator clientTime =
pjq("span[id$=clientDate]").getAttribute(ATTRIBUTE_TITLE);
@Override
public URL getTestUrl() {
@@ -65,7 +70,7 @@
/**
* <p>
- * Test the progress of polling for 3 different values.
+ * Test the progress of polling for 3 different values from client side.
* </p>
*
* <p>
@@ -77,8 +82,9 @@
* </p>
*
* <p>
- * For 5 following poll events it checks that runtime between the events haven't
greater deviation from defined
- * interval than defined {@link #MAX_DEVIATION}.
+ * For 5 following poll events it checks that runtime visible from client (output
from JavaScript's new
+ * Date().getTime()) between the events haven't greater deviation from defined
interval than defined
+ * {@link #MAX_DEVIATION}.
* </p>
*
* <p>
@@ -87,7 +93,7 @@
* </p>
*/
@Test(dataProvider = "templates", groups = "client-side-perf")
- public void testInterval(String templates) {
+ public void testIntervalFromClientPerspective(String templates) {
long total = 0;
long count = 0;
@@ -101,38 +107,49 @@
selenium.getPageExtensions().install();
+ long currentTime = getClientTime();
+
for (int i = 0; i <= TEST_INTERVAL_ITERATIONS; i++) {
long runtime = System.currentTimeMillis();
selenium.getRequestInterceptor().clearRequestTypeDone();
selenium.getRequestInterceptor().waitForRequestTypeChange();
- runtime -= System.currentTimeMillis();
+ runtime -= getClientTime();
if (i > 0) {
+
+ long deviation = Math.abs(interval - Math.abs(runtime));
if (isSeleniumDebug()) {
- System.out.println(runtime);
+ System.out.println(format("deviation for interval {0}:
{1}", interval, deviation));
}
- long deviation = Math.abs(interval - Math.abs(runtime));
assertTrue(deviation <= MAX_DEVIATION, format(
"Particular deviation ({2}) for interval {0} was greater
than {1}", interval, MAX_DEVIATION,
deviation));
total += deviation;
count += 1;
}
+ currentTime += runtime;
}
selenium.uncheck(attributeEnabled);
selenium.fireEvent(attributeEnabled, Event.CHANGE);
selenium.waitForPageToLoad();
}
-
+
long averageDeviation = total / count;
if (isSeleniumDebug()) {
- System.out.println(averageDeviation);
+ System.out.println(format("total average deviation: {0}",
averageDeviation));
}
-
+
assertTrue(averageDeviation <= MAX_AVERAGE_DEVIATION, format(
"Average deviation ({1}) was greater than given maximum {0}",
MAX_AVERAGE_DEVIATION, averageDeviation));
+ }
+ /**
+ * Returns the time of poll event (the time when arrived the response from server)
+ * @return the time of poll event (the time when arrived the response from server)
+ */
+ private long getClientTime() {
+ return asLong(selenium.getAttribute(clientTime));
}
}