Index: third_party/grpc/src/python/grpcio/tests/unit/_cython/_channel_test.py |
diff --git a/third_party/protobuf/src/google/protobuf/arena_nc_test.py b/third_party/grpc/src/python/grpcio/tests/unit/_cython/_channel_test.py |
similarity index 50% |
copy from third_party/protobuf/src/google/protobuf/arena_nc_test.py |
copy to third_party/grpc/src/python/grpcio/tests/unit/_cython/_channel_test.py |
index 87a69b2afd76e6a81adb30e44d7703280535f600..b414f8e6f690771026d4f3b7422bbe089175c1e4 100644 |
--- a/third_party/protobuf/src/google/protobuf/arena_nc_test.py |
+++ b/third_party/grpc/src/python/grpcio/tests/unit/_cython/_channel_test.py |
@@ -1,8 +1,5 @@ |
-#! /usr/bin/env python |
-# |
-# Protocol Buffers - Google's data interchange format |
-# Copyright 2008 Google Inc. All rights reserved. |
-# https://developers.google.com/protocol-buffers/ |
+# Copyright 2016, Google Inc. |
+# All rights reserved. |
# |
# Redistribution and use in source and binary forms, with or without |
# modification, are permitted provided that the following conditions are |
@@ -30,32 +27,57 @@ |
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
-"""Negative compilation unit tests for arena API.""" |
- |
+import time |
+import threading |
import unittest |
-from google3.testing.pybase import fake_target_util |
-import unittest |
+from grpc._cython import cygrpc |
+ |
+# TODO(nathaniel): This should be at least one hundred. Why not one thousand? |
+_PARALLELISM = 4 |
+ |
+ |
+def _channel_and_completion_queue(): |
+ channel = cygrpc.Channel('localhost:54321', cygrpc.ChannelArgs(())) |
+ completion_queue = cygrpc.CompletionQueue() |
+ return channel, completion_queue |
+ |
+ |
+def _connectivity_loop(channel, completion_queue): |
+ for _ in range(100): |
+ connectivity = channel.check_connectivity_state(True) |
+ channel.watch_connectivity_state( |
+ connectivity, cygrpc.Timespec(time.time() + 0.2), completion_queue, |
+ None) |
+ completion_queue.poll(deadline=cygrpc.Timespec(float('+inf'))) |
+ |
+ |
+def _create_loop_destroy(): |
+ channel, completion_queue = _channel_and_completion_queue() |
+ _connectivity_loop(channel, completion_queue) |
+ completion_queue.shutdown() |
+ |
+ |
+def _in_parallel(behavior, arguments): |
+ threads = tuple( |
+ threading.Thread(target=behavior, args=arguments) |
+ for _ in range(_PARALLELISM)) |
+ for thread in threads: |
+ thread.start() |
+ for thread in threads: |
+ thread.join() |
-class ArenaNcTest(unittest.TestCase): |
+class ChannelTest(unittest.TestCase): |
- def testCompilerErrors(self): |
- """Runs a list of tests to verify compiler error messages.""" |
+ def test_single_channel_lonely_connectivity(self): |
+ channel, completion_queue = _channel_and_completion_queue() |
+ _in_parallel(_connectivity_loop, (channel, completion_queue,)) |
+ completion_queue.shutdown() |
- # Defines a list of test specs, where each element is a tuple |
- # (test name, list of regexes for matching the compiler errors). |
- test_specs = [ |
- ('ARENA_PRIVATE_CONSTRUCTOR', |
- [r'calling a protected constructor']), |
- ('SANITY', None)] |
+ def test_multiple_channels_lonely_connectivity(self): |
+ _in_parallel(_create_loop_destroy, ()) |
- fake_target_util.AssertCcCompilerErrors( |
- self, # The current test case. |
- 'google3/google/protobuf/arena_nc', # The fake target file. |
- 'arena_nc.o', # The sub-target to build. |
- test_specs # List of test specifications. |
- ) |
if __name__ == '__main__': |
- unittest.main() |
+ unittest.main(verbosity=2) |