-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathunit_test.py
157 lines (105 loc) · 3.49 KB
/
unit_test.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#!/usr/bin/python3.3
"""
This file is part of multissh.
multissh is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
multissh is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with multissh. If not, see <http://www.gnu.org/licenses/>.
"""
"""
These are tests, some don't work or aren't relevant because of changes to the program
"""
from header import Header
import worker
import launcher as launch
import os
def test_header():
header = Header()
assert(header.size == 0)
assert(header.sequence_number == 0)
header.size = 10
header.sequence_number = 23
assert(header.to_string() == "SIZE=10&SEQUENCE=23\n")
# pipes LOCAL_WORKER ---- pipes ---- pipes ---- REMOTE_WORKER pipes
def test_worker():
LEFT_WORKER_WRITE = "test_write.fifo"
LEFT_WORKER_READ = "test_read.fifo"
try:
os.mkfifo(LEFT_WORKER_READ)
except FileExistsError:
pass
try:
os.mkfifo(LEFT_WORKER_WRITE)
except FileExistsError:
pass
pid = os.fork()
if pid == 0:
left_read = open(LEFT_WORKER_READ, "rb")
left_write = open(LEFT_WORKER_WRITE, "wb")
left_worker = worker.Worker(1, left_read, left_write)
left_worker.poll()
else:
pid = os.fork()
if pid == 0:
right_write = open(LEFT_WORKER_READ, "wb")
right_read = open(LEFT_WORKER_WRITE, "rb")
right_worker = worker.Worker(2, right_read, right_write)
right_worker.poll()
else:
#these will be fifos..
left_multi_write = worker.Worker.get_read_path(str(1))
left_multi_read = worker.Worker.get_write_path(str(1))
try:
os.mkfifo(left_multi_write)
except FileExistsError:
pass
try:
os.mkfifo(left_multi_read)
except FileExistsError:
pass
right_multi_write = worker.Worker.get_read_path(str(2))
right_multi_read = worker.Worker.get_write_path(str(2))
try:
os.mkfifo(right_multi_write)
except FileExistsError:
pass
try:
os.mkfifo(right_multi_read)
except FileExistsError:
pass
left_multi_read = open(left_multi_read, "rb")
left_multi_write = open(left_multi_write, "wb")
right_multi_read = open(right_multi_read, "rb")
right_multi_write = open(right_multi_write, "wb")
# left_multi_read = left_multi_read.buffer
# left_multi_write = left_multi_write.buffer
# right_multi_read = right_multi_read.buffer
# right_multi_write = right_multi_write.buffer
to_send = bytes("helloworld\n", 'UTF-8')
header = Header()
header.sequence_number = 1
header.size = len(to_send)
left_multi_write.write(b''.join([header.to_bytes(), to_send]))
left_multi_write.flush()
assert(right_multi_read.readline() == header.to_bytes())
assert(right_multi_read.readline() == to_send)
right_multi_write.write(b''.join([header.to_bytes(), to_send]))
right_multi_write.flush()
assert(left_multi_read.readline() == header.to_bytes())
assert(left_multi_read.readline() == to_send)
os.unlink(LEFT_WORKER_WRITE)
os.unlink(LEFT_WORKER_READ)
def test_launcher():
args = launch.Launcher.EXECUTABLE_PATH
launcher = launch.Launcher(args)
multiplexer = launcher.launch()
multiplexer.poll()
test_header()
test_worker()
#test_launcher()