-
Notifications
You must be signed in to change notification settings - Fork 245
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added unit test for OneShotServer. Fixed #343
- Loading branch information
Showing
1 changed file
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |