Commit 0903f18e authored by Arnaud Fontaine's avatar Arnaud Fontaine

Add randomSleep() function to simulate an user more realistically.

parent 788a154b
...@@ -69,6 +69,10 @@ def measurementMetaClass(prefix): ...@@ -69,6 +69,10 @@ def measurementMetaClass(prefix):
return a tuple with the time spent on the request and the time spent return a tuple with the time spent on the request and the time spent
on waiting on waiting
""" """
if 'sleep' in kwargs:
minimum_sleep, maximum_sleep = kwargs.pop('sleep')
self.randomSleep(minimum_sleep, maximum_sleep)
ret = method(self, *args, **kwargs) ret = method(self, *args, **kwargs)
if ret is None: if ret is None:
return self.lastRequestSeconds return self.lastRequestSeconds
...@@ -118,6 +122,9 @@ def measurementMetaClass(prefix): ...@@ -118,6 +122,9 @@ def measurementMetaClass(prefix):
return MeasurementMetaClass return MeasurementMetaClass
import random
import time
class Browser(ExtendedTestBrowser): class Browser(ExtendedTestBrowser):
""" """
Implements mechanize tests specific to an ERP5 environment through Implements mechanize tests specific to an ERP5 environment through
...@@ -194,6 +201,28 @@ class Browser(ExtendedTestBrowser): ...@@ -194,6 +201,28 @@ class Browser(ExtendedTestBrowser):
self._logger.debug("Opening url: " + absolute_url) self._logger.debug("Opening url: " + absolute_url)
super(Browser, self).open(absolute_url, data) super(Browser, self).open(absolute_url, data)
def randomSleep(self, minimum, maximum):
"""
Allow to randomly sleep in seconds in the interval [minimum,
maximum] and is meaningful to simulate an user more realistically.
It is also called automatically when passing sleep argument to
click* (C{Link} classes), submit* (C{Form} classes) or open*
(C{Browser} classes) functions, see C{timeInSecondDecorator} wrapper.
@param minimum: Minimum number of seconds to sleep
@type minimum: int
@param maximum: Maximum number of seconds to sleep
@type maximum: int
"""
sleep_time = random.randint(minimum, maximum)
self._logger.debug("Sleeping %ds ([%d, %d])" % (sleep_time,
minimum,
maximum))
time.sleep(sleep_time)
def getCookieValue(self, name, default=None): def getCookieValue(self, name, default=None):
""" """
Get the cookie value of the given cookie name. Get the cookie value of the given cookie name.
...@@ -734,8 +763,6 @@ class MainForm(Form): ...@@ -734,8 +763,6 @@ class MainForm(Form):
""" """
self.submitSelectFavourite(value='/logout') self.submitSelectFavourite(value='/logout')
import time
class ContextMainForm(MainForm): class ContextMainForm(MainForm):
""" """
Class defining context-dependent convenient methods for the main Class defining context-dependent convenient methods for the main
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment