forked from jviereck/rpyc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_win32pipes.py
70 lines (58 loc) · 2.06 KB
/
test_win32pipes.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import sys
import time
import unittest
from threading import Thread
from nose import SkipTest
if sys.platform != "win32":
raise SkipTest("Requires windows")
import rpyc
from rpyc.core.stream import PipeStream, NamedPipeStream
from rpyc.lib.compat import BYTES_LITERAL
class Test_Pipes(unittest.TestCase):
def test_basic_io(self):
p1, p2 = PipeStream.create_pair()
p1.write(BYTES_LITERAL("hello"))
assert p2.poll(0)
assert p2.read(5) == BYTES_LITERAL("hello")
assert not p2.poll(0)
p2.write(BYTES_LITERAL("world"))
assert p1.poll(0)
assert p1.read(5) == BYTES_LITERAL("world")
assert not p1.poll(0)
p1.close()
p2.close()
def test_rpyc(self):
p1, p2 = PipeStream.create_pair()
client = rpyc.connect_stream(p1)
server = rpyc.connect_stream(p2)
server_thread = Thread(target=server.serve_all)
server_thread.start()
assert client.root.get_service_name() == "VOID"
t = rpyc.BgServingThread(client)
assert server.root.get_service_name() == "VOID"
t.stop()
client.close()
server.close()
server_thread.join()
class Test_NamedPipe(object):
def setUp(self):
self.pipe_server_thread = Thread(target=self.pipe_server)
self.pipe_server_thread.start()
time.sleep(1) # make sure server is accepting already
self.np_client = NamedPipeStream.create_client("floop")
self.client = rpyc.connect_stream(self.np_client)
def tearDown(self):
self.client.close()
self.server.close()
self.pipe_server_thread.join()
def pipe_server(self):
self.np_server = NamedPipeStream.create_server("floop")
self.server = rpyc.connect_stream(self.np_server)
self.server.serve_all()
def test_rpyc(self):
assert self.client.root.get_service_name() == "VOID"
t = rpyc.BgServingThread(self.client)
assert self.server.root.get_service_name() == "VOID"
t.stop()
if __name__ == "__main__":
unittest.main()