[Zope-CVS] CVS: Packages/FunctionalTests - CHANGES.txt:1.2 Framework.py:1.16

Tres Seaver tseaver@zope.com
Fri, 12 Apr 2002 15:00:50 -0400


Update of /cvs-repository/Packages/FunctionalTests
In directory cvs.zope.org:/tmp/cvs-serv3347

Modified Files:
	CHANGES.txt Framework.py 
Log Message:
 - Add SleepRequest.

=== Packages/FunctionalTests/CHANGES.txt 1.1 => 1.2 ===
 
+    - Framework: added SleepRequest, to permit injection of "shim" time
+      between real requests.
+
   Release 0.2 -- 2002/03/14
 
     - FTRunner:  added parsing of arbitrary defaults from command-line


=== Packages/FunctionalTests/Framework.py 1.15 => 1.16 ===
         raise NotImplementedError
 
+class SleepRequest( RequestBase ):
+    """
+        "Spacer" request.
+    """
+    def __init__( self, name ):
+
+        self._name = name
+        self._expected_result = 1
+        self._sleep_time = 1.0       # second
+
+    #
+    #   Accessors
+    #
+    def getType( self ):
+        """
+            Return a type string identifying the kind of request
+            (ick!).
+        """
+        return 'SleepRequest'
+
+    def getName( self ):
+        """
+            Return the name of this request within the scenario.
+        """
+        return self._name
+
+    def getExpectedResult( self ):
+        """
+            Return the expected result (return value, HTTP request code,
+            etc.)
+        """
+        return self._expected_result
+
+    def getExpectedTime( self ):
+        """
+            Return the maximum expected time to complete the request.
+        """
+        return self._sleep_time
+
+    def getSleepTime( self ):
+        """
+            Return the time to sleep, in seconds.
+        """
+        return self._sleep_time
+
+    def setSleepTime( self, sleep_time ):
+        """
+            Set the sleep time, in seconds.
+        """
+        self._sleep_time = sleep_time
+
+    def __call__( self, result ):
+        """
+            Invoke the request, storing results in 'result'.
+        """
+        import time
+        time.sleep( self._sleep_time )
+
+def _buildSleepRequest( cp, section ):
+    """
+        Construct a SleepRequest, using the values in 'cp' and 'section'.
+    """
+    r = SleepRequest( section )
+
+    options = cp.options( section )
+
+    if 'sleep' in options:
+        r.setSleepTime( float( cp.get( section, 'sleep' ) ) )
+
+    return r
+
 
 HKEY    = re.compile( r'Header_[0-9]+', re.IGNORECASE )
 HEADER  = re.compile( r'([A-Za-z_][\w_]*)[ ]*=[ ]*(.*)' )
@@ -854,7 +925,9 @@
     """
         Construct a Request, using the values in 'cp' and 'section'.
     """
-    if 'url' in cp.options( section ):
+    if 'sleep' in cp.options( section ):
+        return _buildSleepRequest( cp, section )
+    elif 'url' in cp.options( section ):
         return _buildHTTPRequest( cp, section )
     else:
         return _buildZEORequest( cp, section )
@@ -1043,7 +1116,8 @@
 
             request, requests = requests[0], requests[1:]
             invocation = request( result )
-            result.addInvocation( invocation, request )
+            if invocation is not None:
+                result.addInvocation( invocation, request )
 
             if hasattr( invocation, 'getCookies' ):
                 cookies = invocation.getCookies()