diff --git a/consul/aio.py b/consul/aio.py index 5e347f53..79456ce8 100644 --- a/consul/aio.py +++ b/consul/aio.py @@ -36,7 +36,7 @@ def __del__(self): if not self._session.closed: warnings.warn("Unclosed connector in aio.Consul.HTTPClient", ResourceWarning) - self.close() + self._loop.run_until_complete(self.close()) def get(self, callback, path, params=None): uri = self.uri(path, params) @@ -55,7 +55,7 @@ def post(self, callback, path, params=None, data=''): return self._request(callback, 'POST', uri, data=data) def close(self): - self._session.close() + return self._session.close() class Consul(base.Consul): @@ -70,4 +70,4 @@ def connect(self, host, port, scheme, verify=True, cert=None): def close(self): """Close all opened http connections""" - self.http.close() + return self.http.close() diff --git a/tests/test_aio.py b/tests/test_aio.py index b251231f..3255d8f5 100644 --- a/tests/test_aio.py +++ b/tests/test_aio.py @@ -40,7 +40,7 @@ def main(): assert response is True index, data = yield from c.kv.get('foo') assert data['Value'] == six.b('bar') - c.close() + yield from c.close() loop.run_until_complete(main()) @@ -53,7 +53,7 @@ def main(): yield from c.kv.put('foo', struct.pack('i', 1000)) index, data = yield from c.kv.get('foo') assert struct.unpack('i', data['Value']) == (1000,) - c.close() + yield from c.close() asyncio.set_event_loop(loop) loop.run_until_complete(main()) @@ -65,7 +65,7 @@ def main(): yield from c.kv.put('foo', struct.pack('i', 1000)) index, data = yield from c.kv.get('foo') assert struct.unpack('i', data['Value']) == (1000,) - c.close() + yield from c.close() loop.run_until_complete(main()) @@ -81,7 +81,7 @@ def main(): index, data = yield from c.kv.get('foo', index=index) assert data['Value'] == six.b('bar') yield from fut - c.close() + yield from c.close() @asyncio.coroutine def put(): @@ -102,7 +102,7 @@ def main(): assert response is True index, data = yield from c.kv.get('foo') assert data['Flags'] == 50 - c.close() + yield from c.close() loop.run_until_complete(main()) @@ -124,7 +124,7 @@ def main(): assert response is True index, data = yield from c.kv.get('foo', recurse=True) assert data is None - c.close() + yield from c.close() loop.run_until_complete(main()) @@ -139,7 +139,7 @@ def get(): index, data = yield from c.kv.get('foo', index=index) assert data['Value'] == six.b('bar') yield from fut - c.close() + yield from c.close() @asyncio.coroutine def put(): @@ -161,7 +161,7 @@ def main(): d = {"KV": {"Verb": "get", "Key": "asdf"}} r = yield from c.txn.put([d]) assert r["Results"][0]["KV"]["Value"] == value - c.close() + yield from c.close() loop.run_until_complete(main()) def test_agent_services(self, loop, consul_port): @@ -188,7 +188,7 @@ def main(): assert response is True services = yield from c.agent.services() assert services == {} - c.close() + yield from c.close() loop.run_until_complete(main()) @@ -210,7 +210,7 @@ def nodes(): nodes.remove(current) assert [x['Node'] for x in nodes] == [] yield from fut - c.close() + yield from c.close() @asyncio.coroutine def register(): @@ -239,7 +239,7 @@ def monitor(): index, services = yield from c.session.list(index=index) assert services == [] yield from fut - c.close() + yield from c.close() @asyncio.coroutine def register(): @@ -275,7 +275,7 @@ def main(): destroyed = yield from c.acl.destroy(token) assert destroyed is True - c.close() + yield from c.close() loop.run_until_complete(main())