Skip to content

Commit 561306a

Browse files
author
Chuck Rolke
committed
DISPATCH-2100: TCP half-closed self test
Add a self test that runs if the ncat utility is available. When available run ncat against various TCP listener and connector pairs to verify that half-closed works in a variety of network topologies.
1 parent 42b9bbc commit 561306a

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

tests/system_tests_tcp_adaptor.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,20 @@ class TCP_echo_server(object):
9292
echo_timeout = 30
9393

9494

95+
def ncat_available():
96+
popen_args = ['ncat', '--version']
97+
try:
98+
process = Process(popen_args,
99+
name='ncat_check',
100+
stdout=PIPE,
101+
expect=None,
102+
universal_newlines=True)
103+
out = process.communicate()[0]
104+
return True
105+
except:
106+
return False
107+
108+
95109
#
96110
# Test concurrent clients
97111
#
@@ -881,6 +895,45 @@ def test_60_q2_holdoff(self):
881895
# Declare success
882896
self.logger.log("TCP_TEST Stop %s SUCCESS" % name)
883897

898+
def run_ncat(self, port, logger, expect=Process.EXIT_OK, timeout=2, data=b'abcd'):
899+
ncat_cmd = ['ncat', '127.0.0.1', str(port)]
900+
logger.log("Starting ncat '%s' and input '%s'" % (ncat_cmd, str(data)))
901+
p = self.popen(
902+
ncat_cmd,
903+
stdin=PIPE, stdout=PIPE, stderr=PIPE, expect=expect,
904+
universal_newlines=True)
905+
out = p.communicate(input='abcd', timeout=timeout)[0]
906+
try:
907+
p.teardown()
908+
except Exception as e:
909+
raise Exception(out if out else str(e))
910+
return out
911+
912+
def ncat_runner(self, tname, client, server, logger):
913+
name = "%s_%s_%s" % (tname, client, server)
914+
logger.log(name + " Start")
915+
out = self.run_ncat(TcpAdaptor.tcp_client_listener_ports[client][server], logger, data=b'abcd')
916+
logger.log("run_ncat returns: '%s'" % out)
917+
assert(len(out) > 0)
918+
assert("abcd" in out)
919+
logger.log(tname + " Stop")
920+
921+
# half-closed handling
922+
def test_70_half_closed(self):
923+
if DISABLE_SELECTOR_TESTS:
924+
self.skipTest(DISABLE_SELECTOR_REASON)
925+
if not ncat_available():
926+
self.skipTest("Ncat utility is not available")
927+
name = "test_70_half_closed"
928+
self.logger.log("TCP_TEST Start %s" % name)
929+
self.ncat_runner(name, "INTA", "INTA", self.logger)
930+
self.ncat_runner(name, "INTA", "INTB", self.logger)
931+
self.ncat_runner(name, "INTA", "INTC", self.logger)
932+
self.ncat_runner(name, "EA1", "EA1", self.logger)
933+
self.ncat_runner(name, "EA1", "EB1", self.logger)
934+
self.ncat_runner(name, "EA1", "EC2", self.logger)
935+
self.logger.log("TCP_TEST Stop %s SUCCESS" % name)
936+
884937

885938
class TcpAdaptorManagementTest(TestCase):
886939
"""

0 commit comments

Comments
 (0)