From d4445a1b0576d82c2a2eb6b4497f286ccaa5abf7 Mon Sep 17 00:00:00 2001 From: James Stronz Date: Sat, 27 Jul 2019 01:44:57 -0500 Subject: [PATCH] Added unit test for OneShotServer. Fixed #343 --- tests/test_oneshot_server.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 tests/test_oneshot_server.py diff --git a/tests/test_oneshot_server.py b/tests/test_oneshot_server.py new file mode 100644 index 00000000..a4f57bc7 --- /dev/null +++ b/tests/test_oneshot_server.py @@ -0,0 +1,35 @@ +import time +import rpyc +from rpyc.utils.server import OneShotServer +import unittest + + +class MyService(rpyc.Service): + + def exposed_foo(self): + return "bar" + + +class Test_OneShotServer(unittest.TestCase): + + def setUp(self): + self.server = OneShotServer(MyService, port=18878, auto_register=False) + self.server.logger.quiet = False + self.server._start_in_thread() + + def tearDown(self): + self.server.close() + + def test_server_stops(self): + conn = rpyc.connect("localhost", port=18878) + self.assertEqual("bar", conn.root.foo()) + conn.close() + with self.assertRaises(Exception): + for i in range(3): + conn = rpyc.connect("localhost", port=18878) + conn.close() + time.sleep() + + +if __name__ == "__main__": + unittest.main()