diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/python/grpcio/grpc/framework/foundation/logging_pool.py | 7 | ||||
-rw-r--r-- | src/python/grpcio/tests/unit/framework/foundation/_logging_pool_test.py | 26 |
2 files changed, 28 insertions, 5 deletions
diff --git a/src/python/grpcio/grpc/framework/foundation/logging_pool.py b/src/python/grpcio/grpc/framework/foundation/logging_pool.py index 7c7a6eebfc..f82c7f7fba 100644 --- a/src/python/grpcio/grpc/framework/foundation/logging_pool.py +++ b/src/python/grpcio/grpc/framework/foundation/logging_pool.py @@ -1,4 +1,4 @@ -# Copyright 2015, Google Inc. +# Copyright 2015-2016, Google Inc. # All rights reserved. # # Redistribution and use in source and binary forms, with or without @@ -29,7 +29,6 @@ """A thread pool that logs exceptions raised by tasks executed within it.""" -import functools import logging from concurrent import futures @@ -37,12 +36,12 @@ from concurrent import futures def _wrap(behavior): """Wraps an arbitrary callable behavior in exception-logging.""" - @functools.wraps(behavior) def _wrapping(*args, **kwargs): try: return behavior(*args, **kwargs) except Exception as e: - logging.exception('Unexpected exception from task run in logging pool!') + logging.exception( + 'Unexpected exception from %s executed in logging pool!', behavior) raise return _wrapping diff --git a/src/python/grpcio/tests/unit/framework/foundation/_logging_pool_test.py b/src/python/grpcio/tests/unit/framework/foundation/_logging_pool_test.py index 452802da6a..0521e1c102 100644 --- a/src/python/grpcio/tests/unit/framework/foundation/_logging_pool_test.py +++ b/src/python/grpcio/tests/unit/framework/foundation/_logging_pool_test.py @@ -1,4 +1,4 @@ -# Copyright 2015, Google Inc. +# Copyright 2015-2016, Google Inc. # All rights reserved. # # Redistribution and use in source and binary forms, with or without @@ -29,6 +29,7 @@ """Tests for grpc.framework.foundation.logging_pool.""" +import threading import unittest from grpc.framework.foundation import logging_pool @@ -36,6 +37,21 @@ 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): @@ -59,6 +75,14 @@ class LoggingPoolTest(unittest.TestCase): self.assertIsNotNone(raised_exception) + 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()) + if __name__ == '__main__': unittest.main(verbosity=2) |