This is an automated email from the ASF dual-hosted git repository.
chug pushed a commit to branch dev-protocol-adaptors-2
in repository https://gitbox.apache.org/repos/asf/qpid-dispatch.git
The following commit(s) were added to refs/heads/dev-protocol-adaptors-2 by
this push:
new e29ea39 DISPATCH-1807: Add self tests for tcp protocol adaptor
e29ea39 is described below
commit e29ea396acfab940e54db36b569a865720ac9f8a
Author: Chuck Rolke
AuthorDate: Fri Oct 30 09:40:35 2020 -0400
DISPATCH-1807: Add self tests for tcp protocol adaptor
* echo_server and echo_client modified to have a test class
that runs the test proper.
* tcp_adaptor test runs the client and server test classes in
separate threads and not in separate processes.
This closes #905
---
tests/TCP_echo_client.py | 422 +-
tests/TCP_echo_server.py | 357 +++-
tests/system_tests_tcp_adaptor.py | 147 +++--
3 files changed, 532 insertions(+), 394 deletions(-)
diff --git a/tests/TCP_echo_client.py b/tests/TCP_echo_client.py
index 5f2a687..57152e3 100755
--- a/tests/TCP_echo_client.py
+++ b/tests/TCP_echo_client.py
@@ -19,25 +19,33 @@
# under the License.
#
+from __future__ import unicode_literals
+from __future__ import division
+from __future__ import absolute_import
+from __future__ import print_function
+
import argparse
import os
import selectors
+import signal
import socket
import sys
+from threading import Thread
import time
import traceback
import types
from system_test import Logger
+from system_test import TIMEOUT
+class GracefulKiller:
+ kill_now = False
+ def __init__(self):
+signal.signal(signal.SIGINT, self.exit_gracefully)
+signal.signal(signal.SIGTERM, self.exit_gracefully)
-class EchoLogger(Logger):
-def __init__(self, prefix="ECHO_LOGGER", title="EchoLogger",
print_to_console=False, save_for_dump=False):
-self.prefix = prefix + ' ' if len(prefix) > 0 else ''
-super(EchoLogger, self).__init__(title=title,
print_to_console=print_to_console, save_for_dump=save_for_dump)
-
-def log(self, msg):
-super(EchoLogger, self).log(self.prefix + msg)
+ def exit_gracefully(self,signum, frame):
+self.kill_now = True
def split_chunk_for_display(raw_bytes):
@@ -55,192 +63,240 @@ def split_chunk_for_display(raw_bytes):
return result
-def main_except(host, port, size, count, timeout, logger):
-'''
-:param host: connect to this host
-:param port: connect to this port
-:param size: size of individual payload chunks in bytes
-:param count: number of payload chunks
-:param strategy: "1" Send one payload; # TODO
- Recv one payload
-:param logger: Logger() object
-:return:
-'''
-# Start up
-start_time = time.time()
-logger.log('Connecting to host:%s, port:%d, size:%d, count:%d' % (host,
port, size, count))
-keep_going = True
-total_sent = 0
-total_rcvd = 0
-
-# outbound payload
-payload_out = []
-out_list_idx = 0 # current _out array being sent
-out_byte_idx = 0 # next-to-send in current array
-out_ready_to_send = True
-# Generate unique content for each message so you can tell where the
message
-# or fragment belongs in the whole stream. Chunks look like:
-#b'[localhost:3:6:0]g'
-#host: localhost
-#port: 3
-#index: 6
-#offset into message: 0
-MAGIC_SIZE = 50 # Content repeats after chunks this big - used by echo
server, too
-for idx in range(count):
-body_msg = ""
-padchar = "abcdefghijklmnopqrstuvwxyz@#$%"[idx % 30]
-while len(body_msg) < size:
-chunk = "[%s:%d:%d:%d]" % (host, port, idx, len(body_msg))
-padlen = MAGIC_SIZE - len(chunk)
-chunk += padchar * padlen
-body_msg += chunk
-if len(body_msg) > size:
-body_msg = body_msg[:size]
-payload_out.append(bytearray(body_msg.encode()))
-# incoming payloads
-payload_in = []
-in_list_idx = 0 # current _in array being received
-for i in range(count):
-payload_in.append(bytearray())
-
-# set up connection
-host_address = (host, port)
-sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
-sock.connect(host_address)
-sock.setblocking(False)
-
-# set up selector
-sel = selectors.DefaultSelector()
-sel.register(sock,
- selectors.EVENT_READ | selectors.EVENT_WRITE)
-
-# event loop
-while keep_going:
-if timeout > 0.0:
-elapsed = time.time() - start_time
-if elapsed > timeout:
-logger.log("Exiting due to timeout. Total sent= %d, total
rcvd= %d" % (total_sent, total_rcvd))
-break
-for key, mask in sel.select(timeout=0.1):
-sock =