Skip to content
This repository
Browse code

Adding tests for timeout against rules

  • Loading branch information...
commit 541f26c26dc1fb646aa59d7f7db71e79eafba93a 1 parent 13012f9
David Beitey authored July 19, 2012

Showing 1 changed file with 95 additions and 0 deletions. Show diff stats Hide diff stats

  1. 95  qa/298-Timeout.py
95  qa/298-Timeout.py
... ...
@@ -0,0 +1,95 @@
  1
+from base import *
  2
+
  3
+DIR = "298-Timeout"
  4
+DIR_RULE = "%s-rule" % DIR
  5
+CONTENT = "Tests to check whether timeout is applied."
  6
+
  7
+SERVER_TIMEOUT = 5
  8
+RULE_TIMEOUT = 3
  9
+
  10
+CONF = """
  11
+server!timeout = %(SERVER_TIMEOUT)i
  12
+vserver!1!rule!2890!match = directory
  13
+vserver!1!rule!2890!match!directory = /%(DIR)s
  14
+vserver!1!rule!2890!handler = cgi
  15
+
  16
+vserver!1!rule!2891!match = directory
  17
+vserver!1!rule!2891!match!directory = /%(DIR_RULE)s
  18
+vserver!1!rule!2891!handler = cgi
  19
+vserver!1!rule!2891!timeout = %(RULE_TIMEOUT)i
  20
+
  21
+""" %(globals())
  22
+
  23
+CGI_CODE = """#!/bin/sh
  24
+
  25
+echo "Content-Type: text/plain"
  26
+echo
  27
+sleep %(runtime)i
  28
+echo "%(content)s"
  29
+"""
  30
+
  31
+
  32
+class TestEntry (TestBase):
  33
+    """Test for timeout being applied.
  34
+
  35
+    If timeout expires, no content after `sleep` in the CGI will
  36
+    be delivered.
  37
+    """
  38
+
  39
+    def __init__ (self, dir, filename, runtime, content, expected_timeout):
  40
+        TestBase.__init__ (self, __file__)
  41
+        self.request = "GET /%s/%s HTTP/1.0\r\n" % (dir, filename) +\
  42
+                       "Connection: close\r\n"
  43
+        self.expected_error = 200
  44
+
  45
+        if runtime < expected_timeout:
  46
+            self.expected_content = content
  47
+        else:
  48
+            self.forbidden_content = content
  49
+
  50
+
  51
+class Test (TestCollection):
  52
+
  53
+    def __init__ (self):
  54
+        TestCollection.__init__ (self, __file__)
  55
+
  56
+        self.name = "Connection Timeouts Applied"
  57
+        self.conf = CONF
  58
+        self.proxy_suitable = True
  59
+        self.filenames = {DIR: [],
  60
+                          DIR_RULE: []}
  61
+
  62
+    def Prepare (self, www):
  63
+        self.local_dirs = {DIR: self.Mkdir (www, DIR),
  64
+                           DIR_RULE: self.Mkdir (www, DIR_RULE)}
  65
+
  66
+    def JustBefore (self, www):
  67
+        # Create sub-request objects
  68
+        self.Empty ()
  69
+
  70
+        # Create all tests with different runtime lengths
  71
+        # Instant return and 1 second less than timeout should work,
  72
+        # but past the timeout should return no content.
  73
+        for dir, timeout in ((DIR, SERVER_TIMEOUT), (DIR_RULE, RULE_TIMEOUT)):
  74
+            for script_runtime in (0, timeout-1, timeout+1):
  75
+                # Write the new script files
  76
+                filename = 'test-%i-seconds.cgi' % script_runtime
  77
+                code = CGI_CODE % dict(runtime=script_runtime, content=CONTENT)
  78
+                self.WriteFile (self.local_dirs[dir], filename, 0755, code)
  79
+                self.filenames[dir].append(filename)
  80
+
  81
+                obj = self.Add (TestEntry (dir,
  82
+                                           filename,
  83
+                                           runtime=script_runtime,
  84
+                                           content=CONTENT,
  85
+                                           expected_timeout=timeout))
  86
+
  87
+
  88
+    def JustAfter (self, www):
  89
+        # Clean up the local files
  90
+        for dir in self.local_dirs:
  91
+            for filename in self.filenames[dir]:
  92
+                fp = os.path.join (self.local_dirs[dir], filename)
  93
+                os.unlink (fp)
  94
+        self.filenames = {}
  95
+

0 notes on commit 541f26c

Please sign in to comment.
Something went wrong with that request. Please try again.