_channel_test.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 
15 import threading
16 import time
17 import unittest
18 
19 from grpc._cython import cygrpc
20 
21 from tests.unit.framework.common import test_constants
22 
23 
24 def _channel():
25  return cygrpc.Channel(b'localhost:54321', (), None)
26 
27 
28 def _connectivity_loop(channel):
29  for _ in range(100):
30  connectivity = channel.check_connectivity_state(True)
31  channel.watch_connectivity_state(connectivity, time.time() + 0.2)
32 
33 
35  channel = _channel()
36  _connectivity_loop(channel)
37  channel.close(cygrpc.StatusCode.ok, 'Channel close!')
38 
39 
40 def _in_parallel(behavior, arguments):
41  threads = tuple(
42  threading.Thread(target=behavior, args=arguments)
43  for _ in range(test_constants.THREAD_CONCURRENCY))
44  for thread in threads:
45  thread.start()
46  for thread in threads:
47  thread.join()
48 
49 
50 class ChannelTest(unittest.TestCase):
51 
53  channel = _channel()
54  _connectivity_loop(channel)
55  channel.close(cygrpc.StatusCode.ok, 'Channel close!')
56 
58  _in_parallel(_create_loop_destroy, ())
59 
61  channel = _channel()
62  connectivity = channel.check_connectivity_state(True)
63  channel.watch_connectivity_state(connectivity, -3.14)
64  channel.close(cygrpc.StatusCode.ok, 'Channel close!')
65  # NOTE(lidiz) The negative timeout should not trigger SIGABRT.
66  # Bug report: https://github.com/grpc/grpc/issues/18244
67 
68 
69 if __name__ == '__main__':
70  unittest.main(verbosity=2)
capstone.range
range
Definition: third_party/bloaty/third_party/capstone/bindings/python/capstone/__init__.py:6
tests.unit._cython._channel_test._create_loop_destroy
def _create_loop_destroy()
Definition: _channel_test.py:34
tests.unit._cython._channel_test.ChannelTest.test_multiple_channels_lonely_connectivity
def test_multiple_channels_lonely_connectivity(self)
Definition: _channel_test.py:57
tests.unit._cython._channel_test._connectivity_loop
def _connectivity_loop(channel)
Definition: _channel_test.py:28
tests.unit._cython._channel_test._in_parallel
def _in_parallel(behavior, arguments)
Definition: _channel_test.py:40
tests.unit._cython._channel_test._channel
def _channel()
Definition: _channel_test.py:24
tests.unit._cython._channel_test.ChannelTest.test_negative_deadline_connectivity
def test_negative_deadline_connectivity(self)
Definition: _channel_test.py:60
tests.unit._cython._channel_test.ChannelTest
Definition: _channel_test.py:50
grpc._cython
Definition: src/python/grpcio/grpc/_cython/__init__.py:1
tests.unit.framework.common
Definition: src/python/grpcio_tests/tests/unit/framework/common/__init__.py:1
tests.unit._cython._channel_test.ChannelTest.test_single_channel_lonely_connectivity
def test_single_channel_lonely_connectivity(self)
Definition: _channel_test.py:52


grpc
Author(s):
autogenerated on Thu Mar 13 2025 02:58:27