1# Copyright 2019 The 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"""Test for gRPC Python debug example.""" 15 16from __future__ import absolute_import 17from __future__ import division 18from __future__ import print_function 19 20import logging 21import unittest 22 23from examples.python.debug import debug_server 24from examples.python.debug import send_message 25from examples.python.debug import get_stats 26 27_LOGGER = logging.getLogger(__name__) 28_LOGGER.setLevel(logging.INFO) 29 30_FAILURE_RATE = 0.5 31_NUMBER_OF_MESSAGES = 100 32 33_ADDR_TEMPLATE = 'localhost:%d' 34 35 36class DebugExampleTest(unittest.TestCase): 37 38 def test_channelz_example(self): 39 server = debug_server.create_server(addr='[::]:0', 40 failure_rate=_FAILURE_RATE) 41 port = server.add_insecure_port('[::]:0') 42 server.start() 43 address = _ADDR_TEMPLATE % port 44 45 send_message.run(addr=address, n=_NUMBER_OF_MESSAGES) 46 get_stats.run(addr=address) 47 server.stop(None) 48 # No unhandled exception raised, test passed! 49 50 51if __name__ == '__main__': 52 logging.basicConfig() 53 unittest.main(verbosity=2) 54