Debian Codegraph @

python/tests/proton_tests/soak.py

raw
1 from __future__ import absolute_import
2 #
3 # Licensed to the Apache Software Foundation (ASF) under one
4 # or more contributor license agreements. See the NOTICE file
5 # distributed with this work for additional information
6 # regarding copyright ownership. The ASF licenses this file
7 # to you under the Apache License, Version 2.0 (the
8 # "License"); you may not use this file except in compliance
9 # with the License. You may obtain a copy of the License at
10 #
11 # http://www.apache.org/licenses/LICENSE-2.0
12 #
13 # Unless required by applicable law or agreed to in writing,
14 # software distributed under the License is distributed on an
15 # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 # KIND, either express or implied. See the License for the
17 # specific language governing permissions and limitations
18 # under the License.
19 #
20
21 from __future__ import absolute_import
22
23 import os
24
25 from .common import Test, Skipped, free_tcp_ports, \
26 MessengerReceiverC, MessengerSenderC, \
27 ReactorReceiverC, ReactorSenderC, \
28 isSSLPresent
29
30 #
31 # Tests that run the apps
32 #
33
34
35 class AppTests(Test):
36
37 def __init__(self, *args):
38 Test.__init__(self, *args)
39 self.is_valgrind = False
40
41 def default(self, name, value, **kwargs):
42 if self.is_valgrind:
43 default = kwargs.get("valgrind", value)
44 else:
45 default = value
46 return Test.default(self, name, default, **kwargs)
47
48 @property
49 def iterations(self):
50 return int(self.default("iterations", 2, fast=1, valgrind=2))
51
52 @property
53 def send_count(self):
54 return int(self.default("send_count", 17, fast=1, valgrind=2))
55
56 @property
57 def target_count(self):
58 return int(self.default("target_count", 5, fast=1, valgrind=2))
59
60 @property
61 def send_batch(self):
62 return int(self.default("send_batch", 7, fast=1, valgrind=2))
63
64 @property
65 def forward_count(self):
66 return int(self.default("forward_count", 5, fast=1, valgrind=2))
67
68 @property
69 def port_count(self):
70 return int(self.default("port_count", 3, fast=1, valgrind=2))
71
72 @property
73 def sender_count(self):
74 return int(self.default("sender_count", 3, fast=1, valgrind=2))
75
76 def valgrind_test(self):
77 self.is_valgrind = True
78
79 def setUp(self):
80 self.senders = []
81 self.receivers = []
82
83 def tearDown(self):
84 pass
85
86 def _do_test(self, iterations=1):
87 verbose = self.verbose
88
89 for R in self.receivers:
90 R.start(verbose)
91
92 for j in range(iterations):
93 for S in self.senders:
94 S.start(verbose)
95
96 for S in self.senders:
97 S.wait()
98 #print("SENDER OUTPUT:")
99 #print( S.stdout() )
100 assert S.status() == 0, ("Command '%s' failed status=%d: '%s' '%s'"
101 % (str(S.cmdline()),
102 S.status(),
103 S.stdout(),
104 S.stderr()))
105
106 for R in self.receivers:
107 R.wait()
108 #print("RECEIVER OUTPUT")
109 #print( R.stdout() )
110 assert R.status() == 0, ("Command '%s' failed status=%d: '%s' '%s'"
111 % (str(R.cmdline()),
112 R.status(),
113 R.stdout(),
114 R.stderr()))
115
116 #
117 # Traffic passing tests based on the Messenger apps
118 #
119
120
121 class MessengerTests(AppTests):
122
123 _timeout = 60
124
125 def _ssl_check(self):
126 if not isSSLPresent():
127 raise Skipped("No SSL libraries found.")
128 if os.name == "nt":
129 raise Skipped("Windows SChannel lacks anonymous cipher support.")
130
131 def __init__(self, *args):
132 AppTests.__init__(self, *args)
133
134 def _do_oneway_test(self, receiver, sender, domain="amqp"):
135 """ Send N messages to a receiver.
136 Parameters:
137 iterations - repeat the senders this many times
138 target_count = # of targets to send to.
139 send_count = # messages sent to each target
140 """
141 iterations = self.iterations
142 send_count = self.send_count
143 target_count = self.target_count
144
145 send_total = send_count * target_count
146 receive_total = send_total * iterations
147
148 port = free_tcp_ports()[0]
149
150 receiver.subscriptions = ["%s://~0.0.0.0:%s" % (domain, port)]
151 receiver.receive_count = receive_total
152 receiver.timeout = MessengerTests._timeout
153 self.receivers.append(receiver)
154
155 sender.targets = ["%s://0.0.0.0:%s/X%d" % (domain, port, j) for j in range(target_count)]
156 sender.send_count = send_total
157 sender.timeout = MessengerTests._timeout
158 self.senders.append(sender)
159
160 self._do_test(iterations)
161
162 def _do_echo_test(self, receiver, sender, domain="amqp"):
163 """ Send N messages to a receiver, which responds to each.
164 Parameters:
165 iterations - repeat the senders this many times
166 target_count - # targets to send to
167 send_count = # messages sent to each target
168 send_batch - wait for replies after this many messages sent
169 """
170 iterations = self.iterations
171 send_count = self.send_count
172 target_count = self.target_count
173 send_batch = self.send_batch
174
175 send_total = send_count * target_count
176 receive_total = send_total * iterations
177
178 port = free_tcp_ports()[0]
179
180 receiver.subscriptions = ["%s://~0.0.0.0:%s" % (domain, port)]
181 receiver.receive_count = receive_total
182 receiver.send_reply = True
183 receiver.timeout = MessengerTests._timeout
184 self.receivers.append(receiver)
185
186 sender.targets = ["%s://0.0.0.0:%s/%dY" % (domain, port, j) for j in range(target_count)]
187 sender.send_count = send_total
188 sender.get_reply = True
189 sender.send_batch = send_batch
190 sender.timeout = MessengerTests._timeout
191 self.senders.append(sender)
192
193 self._do_test(iterations)
194
195 # Removed messenger "relay" tests. The test start-up is faulty:
196 # msgr-recv prints it's -X ready message when it starts to open a
197 # connection but it does not wait for the remote open. The relay
198 # tests depends on mapping a container name from an incoming
199 # connection. They can fail under if the sender starts before the
200 # connection is complete (esp. valgrind with SSL connections) We
201 # could fix the tests but since messenger is deprecated it does
202 # not seem worthwhile.
203
204 def _do_star_topology_test(self, r_factory, s_factory, domain="amqp"):
205 """
206 A star-like topology, with a central receiver at the hub, and senders at
207 the spokes. Each sender will connect to each of the ports the receiver is
208 listening on. Each sender will then create N links per each connection.
209 Each sender will send X messages per link, waiting for a response.
210 Parameters:
211 iterations - repeat the senders this many times
212 port_count - # of ports the receiver will listen on. Each sender connects
213 to all ports.
214 sender_count - # of senders
215 target_count - # of targets per connection
216 send_count - # of messages sent to each target
217 send_batch - # of messages to send before waiting for response
218 """
219 iterations = self.iterations
220 port_count = self.port_count
221 sender_count = self.sender_count
222 target_count = self.target_count
223 send_count = self.send_count
224 send_batch = self.send_batch
225
226 send_total = port_count * target_count * send_count
227 receive_total = send_total * sender_count * iterations
228
229 ports = free_tcp_ports(port_count)
230
231 receiver = r_factory()
232 receiver.subscriptions = ["%s://~0.0.0.0:%s" % (domain, port) for port in ports]
233 receiver.receive_count = receive_total
234 receiver.send_reply = True
235 receiver.timeout = MessengerTests._timeout
236 self.receivers.append(receiver)
237
238 for i in range(sender_count):
239 sender = s_factory()
240 sender.targets = ["%s://0.0.0.0:%s/%d" % (domain, port, j) for port in ports for j in range(target_count)]
241 sender.send_count = send_total
242 sender.send_batch = send_batch
243 sender.get_reply = True
244 sender.timeout = MessengerTests._timeout
245 self.senders.append(sender)
246
247 self._do_test(iterations)
248
249 def test_oneway_C(self):
250 self._do_oneway_test(MessengerReceiverC(), MessengerSenderC())
251
252 def test_oneway_C_SSL(self):
253 self._ssl_check()
254 self._do_oneway_test(MessengerReceiverC(), MessengerSenderC(), "amqps")
255
256 def test_echo_C(self):
257 self._do_echo_test(MessengerReceiverC(), MessengerSenderC())
258
259 def test_echo_C_SSL(self):
260 self._ssl_check()
261 self._do_echo_test(MessengerReceiverC(), MessengerSenderC(), "amqps")
262
263 def test_star_topology_C(self):
264 self._do_star_topology_test(MessengerReceiverC, MessengerSenderC)
265
266 def test_star_topology_C_SSL(self):
267 self._ssl_check()
268 self._do_star_topology_test(MessengerReceiverC, MessengerSenderC, "amqps")
269
270 def test_oneway_reactor(self):
271 self._do_oneway_test(ReactorReceiverC(), ReactorSenderC())