Index: third_party/grpc/src/python/grpcio/tests/unit/framework/foundation/_logging_pool_test.py |
diff --git a/third_party/protobuf/src/google/protobuf/arena_nc_test.py b/third_party/grpc/src/python/grpcio/tests/unit/framework/foundation/_logging_pool_test.py |
similarity index 51% |
copy from third_party/protobuf/src/google/protobuf/arena_nc_test.py |
copy to third_party/grpc/src/python/grpcio/tests/unit/framework/foundation/_logging_pool_test.py |
index 87a69b2afd76e6a81adb30e44d7703280535f600..0521e1c102ace797f2f841a4ea2e3bd72e248bfe 100644 |
--- a/third_party/protobuf/src/google/protobuf/arena_nc_test.py |
+++ b/third_party/grpc/src/python/grpcio/tests/unit/framework/foundation/_logging_pool_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 2015-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,62 @@ |
# (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.""" |
+"""Tests for grpc.framework.foundation.logging_pool.""" |
+import threading |
import unittest |
-from google3.testing.pybase import fake_target_util |
-import unittest |
+from grpc.framework.foundation import logging_pool |
+ |
+_POOL_SIZE = 16 |
+ |
+ |
+class _CallableObject(object): |
+ |
+ def __init__(self): |
+ self._lock = threading.Lock() |
+ self._passed_values = [] |
+ |
+ def __call__(self, value): |
+ with self._lock: |
+ self._passed_values.append(value) |
+ |
+ def passed_values(self): |
+ with self._lock: |
+ return tuple(self._passed_values) |
+ |
+ |
+class LoggingPoolTest(unittest.TestCase): |
+ |
+ def testUpAndDown(self): |
+ pool = logging_pool.pool(_POOL_SIZE) |
+ pool.shutdown(wait=True) |
+ |
+ with logging_pool.pool(_POOL_SIZE) as pool: |
+ self.assertIsNotNone(pool) |
+ |
+ def testTaskExecuted(self): |
+ test_list = [] |
+ |
+ with logging_pool.pool(_POOL_SIZE) as pool: |
+ pool.submit(lambda: test_list.append(object())).result() |
+ self.assertTrue(test_list) |
-class ArenaNcTest(unittest.TestCase): |
+ def testException(self): |
+ with logging_pool.pool(_POOL_SIZE) as pool: |
+ raised_exception = pool.submit(lambda: 1/0).exception() |
- def testCompilerErrors(self): |
- """Runs a list of tests to verify compiler error messages.""" |
+ self.assertIsNotNone(raised_exception) |
- # 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 testCallableObjectExecuted(self): |
+ callable_object = _CallableObject() |
+ passed_object = object() |
+ with logging_pool.pool(_POOL_SIZE) as pool: |
+ future = pool.submit(callable_object, passed_object) |
+ self.assertIsNone(future.result()) |
+ self.assertSequenceEqual((passed_object,), callable_object.passed_values()) |
- 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) |