diff options
author | 2016-01-26 21:39:24 +0000 | |
---|---|---|
committer | 2016-01-26 21:39:24 +0000 | |
commit | 8fff90d3a9657f9733c2bc15ed53b245f68139d4 (patch) | |
tree | 3ddae658932faf20b2d2df4122e684a4b11d9230 /src/python/grpcio/tests | |
parent | a847f51c94e90d4c1a67b9c29a8206454c1bcc17 (diff) |
Drop use of functools.wrap in logging_pool
functools.wrap is only warranted to work with functions and methods but
logging_pool is warranted to work with callable behaviors, so using
functools.wrap has been wrong all along.
The particular incompatibility motivating this correction is that
callable objects do not have a "__name__" attribute.
Diffstat (limited to 'src/python/grpcio/tests')
-rw-r--r-- | src/python/grpcio/tests/unit/framework/foundation/_logging_pool_test.py | 26 |
1 files changed, 25 insertions, 1 deletions
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) |