From 944715554d719e19a8ac12a2a5b9e874db72c3a0 Mon Sep 17 00:00:00 2001 From: Claudio-Daniel Freire Date: Wed, 13 Apr 2011 16:56:43 +0200 Subject: [PATCH] Ticket #24: test auto-reconnection --- test/util/server.py | 53 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/test/util/server.py b/test/util/server.py index a70e4499..e4155fce 100755 --- a/test/util/server.py +++ b/test/util/server.py @@ -47,6 +47,29 @@ class ServerTestCase(unittest.TestCase): reply = c.read_reply() self.assertTrue(reply == "Stopping server") + def test_server_auto_reconnect(self): + s = server.Server(self.root_dir) + s.run() + c = server.Client(self.root_dir) + + c.send_msg("Hola") + reply = c.read_reply() + self.assertTrue(reply == "Reply to: Hola") + + # purposedly break the connection + c._process.stdin.close() + c._process.stdout.close() + c._process.stderr.close() + + # assert that the communication works (possible with auto-reconnection) + c.send_msg("Hola") + reply = c.read_reply() + self.assertTrue(reply == "Reply to: Hola") + + c.send_stop() + reply = c.read_reply() + self.assertTrue(reply == "Stopping server") + def test_server_long_message(self): s = server.Server(self.root_dir) s.run() @@ -107,6 +130,36 @@ class ServerTestCase(unittest.TestCase): reply = c.read_reply() self.assertTrue(reply == "Stopping server") + def test_ssh_server_auto_reconnect(self): + env = test_util.test_environment() + user = getpass.getuser() + # launch server + python_code = "from nepi.util import server;s=server.Server('%s');\ + s.run()" % self.root_dir + server.popen_ssh_subprocess(python_code, host = "localhost", + port = env.port, user = user, agent = True) + + c = server.Client(self.root_dir, host = "localhost", port = env.port, + user = user, agent = True) + + c.send_msg("Hola") + reply = c.read_reply() + self.assertTrue(reply == "Reply to: Hola") + + # purposedly break the connection + c._process.stdin.close() + c._process.stdout.close() + c._process.stderr.close() + + # assert that the communication works (possible with auto-reconnection) + c.send_msg("Hola") + reply = c.read_reply() + self.assertTrue(reply == "Reply to: Hola") + + c.send_stop() + reply = c.read_reply() + self.assertTrue(reply == "Stopping server") + def tearDown(self): shutil.rmtree(self.root_dir) -- 2.43.0