test_runner.py
Go to the documentation of this file.
1 # Copyright 2016 gRPC authors.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 """Thread that sends random weighted requests on a TestService stub."""
15 
16 import random
17 import threading
18 import time
19 import traceback
20 
21 
22 def _weighted_test_case_generator(weighted_cases):
23  weight_sum = sum(weighted_cases.itervalues())
24 
25  while True:
26  val = random.uniform(0, weight_sum)
27  partial_sum = 0
28  for case in weighted_cases:
29  partial_sum += weighted_cases[case]
30  if val <= partial_sum:
31  yield case
32  break
33 
34 
35 class TestRunner(threading.Thread):
36 
37  def __init__(self, stub, test_cases, hist, exception_queue, stop_event):
38  super(TestRunner, self).__init__()
39  self._exception_queue = exception_queue
40  self._stop_event = stop_event
41  self._stub = stub
43  self._histogram = hist
44 
45  def run(self):
46  while not self._stop_event.is_set():
47  try:
48  test_case = next(self._test_cases)
49  start_time = time.time()
50  test_case.test_interoperability(self._stub, None)
51  end_time = time.time()
52  self._histogram.add((end_time - start_time) * 1e9)
53  except Exception as e: # pylint: disable=broad-except
54  traceback.print_exc()
55  self._exception_queue.put(
56  Exception(
57  "An exception occurred during test {}".format(
58  test_case), e))
tests.stress.test_runner.TestRunner._stub
_stub
Definition: test_runner.py:41
http2_test_server.format
format
Definition: http2_test_server.py:118
tests.stress.test_runner.TestRunner.__init__
def __init__(self, stub, test_cases, hist, exception_queue, stop_event)
Definition: test_runner.py:37
grpc::testing::sum
double sum(const T &container, F functor)
Definition: test/cpp/qps/stats.h:30
tests.stress.test_runner.TestRunner._exception_queue
_exception_queue
Definition: test_runner.py:39
tests.stress.test_runner.TestRunner._test_cases
_test_cases
Definition: test_runner.py:42
add
static void add(const char *beg, const char *end, char ***ss, size_t *ns)
Definition: debug/trace.cc:96
tests.stress.test_runner.TestRunner
Definition: test_runner.py:35
tests.stress.test_runner.TestRunner.run
def run(self)
Definition: test_runner.py:45
tests.stress.test_runner.TestRunner._histogram
_histogram
Definition: test_runner.py:43
next
AllocList * next[kMaxLevel]
Definition: abseil-cpp/absl/base/internal/low_level_alloc.cc:100
tests.stress.test_runner.TestRunner._stop_event
_stop_event
Definition: test_runner.py:40
tests.stress.test_runner._weighted_test_case_generator
def _weighted_test_case_generator(weighted_cases)
Definition: test_runner.py:22


grpc
Author(s):
autogenerated on Thu Mar 13 2025 03:01:31