This is an automated email from the ASF dual-hosted git repository.

sorber pushed a commit to branch 6.2.x
in repository https://git-dual.apache.org/repos/asf/trafficserver.git

commit 678a2dc973b5b1f7b2f62930e9b4948834ab180b
Author: Thomas Jackson <jackso...@apache.org>
AuthorDate: Wed Apr 6 19:50:19 2016 -0700

    TS-4328: Add a test for the slow response case
    
    If the request hits a timeout-- but we sent the request to the origin we 
cannot rety the request
    
    (cherry picked from commit a6e89ed4ea1a67613c27a4136e3a7a58ef7aead7)
---
 ci/tsqa/tests/test_connect_attempts.py | 42 ++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)

diff --git a/ci/tsqa/tests/test_connect_attempts.py 
b/ci/tsqa/tests/test_connect_attempts.py
index 58d70e1..fc037ae 100644
--- a/ci/tsqa/tests/test_connect_attempts.py
+++ b/ci/tsqa/tests/test_connect_attempts.py
@@ -111,6 +111,36 @@ def thread_partial_response(sock):
             connection.close()
 
 
+def thread_slow_response(sock):
+    '''
+    Thread to sleep a decreasing amount of time before sending the response
+
+    sleep times: 2 -> 1 -> 0
+    '''
+    sock.listen(0)
+    sleep_time = 2
+    num_requests = 0
+    # poll
+    while True:
+        select.select([sock], [], [])
+        try:
+            connection, addr = sock.accept()
+            time.sleep(sleep_time)
+            connection.send((
+                'HTTP/1.1 200 OK\r\n'
+                'Content-Length: {body_len}\r\n'
+                'Content-Type: text/html; charset=UTF-8\r\n'
+                'Connection: 
close\r\n\r\n{body}'.format(body_len=len(str(num_requests)), body=num_requests)
+            ))
+            connection.close()
+            num_requests += 1
+        except Exception as e:
+            print 'connection died!', e
+            pass
+        if sleep_time > 0:
+            sleep_time -= 1
+
+
 class TestOriginServerConnectAttempts(helpers.EnvironmentCase):
     @classmethod
     def setUpEnv(cls, env):
@@ -149,6 +179,11 @@ class 
TestOriginServerConnectAttempts(helpers.EnvironmentCase):
         t.daemon = True
         t.start()
 
+        sock = _add_sock('slow_response')
+        t = threading.Thread(target=thread_slow_response, args=(sock,))
+        t.daemon = True
+        t.start()
+
         sock = _add_sock('partial_response')
         t = threading.Thread(target=thread_partial_response, args=(sock,))
         t.daemon = True
@@ -209,3 +244,10 @@ class 
TestOriginServerConnectAttempts(helpers.EnvironmentCase):
         # make sure its not the first one (otherwise the test messed up 
somehow)
         print ret.text
         self.assertGreater(int(ret.text), 0)
+
+    def test_slow_response(self):
+        '''Verify that we get 5xx from origins that take longer than 
acceptable, since we will not retry them'''
+        url = 
'http://127.0.0.1:{0}/slow_response/s'.format(self.configs['records.config']['CONFIG']['proxy.config.http.server_ports'])
+        ret = requests.get(url)
+        # make sure it worked
+        self.assertEqual(ret.status_code, 504)

-- 
To stop receiving notification emails like this one, please contact
"commits@trafficserver.apache.org" <commits@trafficserver.apache.org>.

Reply via email to