trafficserver-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a..@apache.org
Subject [trafficserver] branch master updated: consolidates functionality into one tcp_client
Date Sun, 17 Sep 2017 01:53:58 GMT
This is an automated email from the ASF dual-hosted git repository.

amc pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git


The following commit(s) were added to refs/heads/master by this push:
     new 1b5be26  consolidates functionality into one tcp_client
1b5be26 is described below

commit 1b5be2666e940e7d77c009872fb2ebf37f0aed34
Author: Derek Dagit <derekd@oath.com>
AuthorDate: Fri Sep 15 18:06:09 2017 +0000

    consolidates functionality into one tcp_client
---
 tests/gold_tests/headers/data/www.http408.test.txt |  5 ++
 tests/gold_tests/headers/http408.test.py           | 18 +++---
 tests/tools/tcp_408_client.py                      | 64 ----------------------
 tests/tools/tcp_client.py                          | 23 +++++---
 4 files changed, 29 insertions(+), 81 deletions(-)

diff --git a/tests/gold_tests/headers/data/www.http408.test.txt b/tests/gold_tests/headers/data/www.http408.test.txt
new file mode 100644
index 0000000..81f9f98
--- /dev/null
+++ b/tests/gold_tests/headers/data/www.http408.test.txt
@@ -0,0 +1,5 @@
+POST / HTTP/1.1
+Host: www.http408.test
+Content-Length: 100
+
+arbitrary content
\ No newline at end of file
diff --git a/tests/gold_tests/headers/http408.test.py b/tests/gold_tests/headers/http408.test.py
index 7621c77..b7b7137 100644
--- a/tests/gold_tests/headers/http408.test.py
+++ b/tests/gold_tests/headers/http408.test.py
@@ -24,35 +24,35 @@ Test.Summary = '''
 Check 408 response header for protocol stack data.
 '''
 
-Test.SkipUnless(
-)
 Test.ContinueOnFail = True
 
 # Define default ATS
 ts = Test.MakeATSProcess("ts")
 server = Test.MakeOriginServer("server")
 
-testName = "408 test"
+HTTP_408_HOST = 'www.http408.test'
 
-request_header = {"headers": "GET / HTTP/1.1\r\nHost: www.example.com\r\n\r\n", "timestamp":
"1469733493.993", "body": ""}
+request_header = {"headers": "GET / HTTP/1.1\r\nHost: {}\r\n\r\n".format(HTTP_408_HOST),
"timestamp": "1469733493.993", "body": ""}
 response_header = {"headers": "HTTP/1.1 200 OK\r\nConnection: close\r\n\r\n", "timestamp":
"1469733493.993", "body": ""}
 server.addResponse("sessionlog.json", request_header, response_header)
 
 ts.Disk.remap_config.AddLine(
-    'map http://www.example.com http://127.0.0.1:{0}'.format(server.Variables.Port)
+    'map http://{0} http://127.0.0.1:{1}'.format(HTTP_408_HOST, server.Variables.Port)
 )
 
+TIMEOUT=2
 ts.Disk.records_config.update({
-    'proxy.config.http.transaction_no_activity_timeout_in': 2,
+    'proxy.config.http.transaction_no_activity_timeout_in': TIMEOUT,
 })
 
-Test.Setup.Copy(os.path.join(os.pardir, os.pardir, 'tools', 'tcp_408_client.py'))
+Test.Setup.Copy(os.path.join(os.pardir, os.pardir, 'tools', 'tcp_client.py'))
+Test.Setup.Copy('data')
 
 tr = Test.AddTestRun()
 tr.Processes.Default.StartBefore(server)
 tr.Processes.Default.StartBefore(Test.Processes.ts)
-tr.Processes.Default.Command = 'python tcp_408_client.py 127.0.0.1 {0} 4'.format(
-    ts.Variables.port)
+tr.Processes.Default.Command = 'python tcp_client.py 127.0.0.1 {0} {1} --delay-after-send
{2}'\
+        .format(ts.Variables.port, 'data/{0}.txt'.format(HTTP_408_HOST), TIMEOUT + 2)
 tr.Processes.Default.ReturnCode = 0
 tr.Processes.Default.TimeOut = 10
 tr.Processes.Default.Streams.stdout = "http408.gold"
diff --git a/tests/tools/tcp_408_client.py b/tests/tools/tcp_408_client.py
deleted file mode 100644
index de53697..0000000
--- a/tests/tools/tcp_408_client.py
+++ /dev/null
@@ -1,64 +0,0 @@
-'''
-A simple command line interface to send/receive bytes over TCP.
-'''
-#  Licensed to the Apache Software Foundation (ASF) under one
-#  or more contributor license agreements.  See the NOTICE file
-#  distributed with this work for additional information
-#  regarding copyright ownership.  The ASF licenses this file
-#  to you under the Apache License, Version 2.0 (the
-#  "License"); you may not use this file except in compliance
-#  with the License.  You may obtain a copy of the License at
-#
-#      http://www.apache.org/licenses/LICENSE-2.0
-#
-#  Unless required by applicable law or agreed to in writing, software
-#  distributed under the License is distributed on an "AS IS" BASIS,
-#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-#  See the License for the specific language governing permissions and
-#  limitations under the License.
-
-import argparse
-import socket
-import sys
-import time
-
-
-def tcp_client(host, port, sleep, header, data):
-    pass
-    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
-    s.connect((host, port))
-    s.sendall(header.encode())
-    s.sendall(data[0].encode())
-    time.sleep(sleep)
-    s.shutdown(socket.SHUT_WR)
-    while True:
-        output = s.recv(4096)  # suggested bufsize from docs.python.org
-        if len(output) <= 0:
-            break
-        else:
-            sys.stdout.write(output.decode())
-    s.close()
-
-
-DESCRIPTION =\
-    """A simple command line interface to send/receive bytes over TCP.
-
-The full contents of the given file are sent via a TCP connection to the given
-host and port. Then data is read from the connection and printed to standard
-output. Streaming is not supported."""
-
-
-def main(argv):
-    parser = argparse.ArgumentParser(description=DESCRIPTION)
-    parser.add_argument('host', help='the target host')
-    parser.add_argument('port', type=int, help='the target port')
-    parser.add_argument('sleep', type=int, help='timeout')
-    args = parser.parse_args()
-
-    header = 'POST / HTTP/1.1\r\nHost: www.example.com\r\nContent-Length: 2\r\n\r\n'
-    data = "aa"
-    tcp_client(args.host, args.port, args.sleep, header, data)
-
-
-if __name__ == "__main__":
-    main(sys.argv)
diff --git a/tests/tools/tcp_client.py b/tests/tools/tcp_client.py
index 71f14e7..fba05c4 100644
--- a/tests/tools/tcp_client.py
+++ b/tests/tools/tcp_client.py
@@ -20,13 +20,14 @@ A simple command line interface to send/receive bytes over TCP.
 import argparse
 import socket
 import sys
+import time
 
-
-def tcp_client(host, port, data):
-    pass
+def tcp_client(host, port, data, closeDelaySeconds=0):
     s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
     s.connect((host, port))
     s.sendall(data.encode())
+    if closeDelaySeconds > 0:
+        time.sleep(closeDelaySeconds)
     s.shutdown(socket.SHUT_WR)
     while True:
         output = s.recv(4096)  # suggested bufsize from docs.python.org
@@ -38,25 +39,31 @@ def tcp_client(host, port, data):
 
 
 DESCRIPTION =\
-    """A simple command line interface to send/receive bytes over TCP.
+    """
+A simple command line interface to send/receive bytes over TCP.
 
 The full contents of the given file are sent via a TCP connection to the given
 host and port. Then data is read from the connection and printed to standard
-output. Streaming is not supported."""
+output. Streaming is not supported.
+
+If a delay is specified, the client will pause before closing the connections
+to further writes. This is useful to simulate the sending of partial data.
+"""
 
 
 def main(argv):
-    parser = argparse.ArgumentParser(description=DESCRIPTION)
+    parser = argparse.ArgumentParser(description=DESCRIPTION,\
+            formatter_class=argparse.RawDescriptionHelpFormatter)
     parser.add_argument('host', help='the target host')
     parser.add_argument('port', type=int, help='the target port')
     parser.add_argument('file', help='the file with content to be sent')
+    parser.add_argument('--delay-after-send', metavar='SECONDS', type=int, help='after send,
delay in seconds before half-close', default=0 )
     args = parser.parse_args()
 
     data = ''
     with open(args.file, 'r') as f:
         data = f.read()
-
-    tcp_client(args.host, args.port, data)
+    tcp_client(args.host, args.port, data, args.delay_after_send)
 
 
 if __name__ == "__main__":

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

Mime
View raw message