🌐 AI搜索 & 代理 主页
Skip to content
This repository was archived by the owner on Apr 15, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions consul/aio.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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):
Expand All @@ -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()
24 changes: 12 additions & 12 deletions tests/test_aio.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand All @@ -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())
Expand All @@ -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())

Expand All @@ -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():
Expand All @@ -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())

Expand All @@ -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())

Expand All @@ -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():
Expand All @@ -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):
Expand All @@ -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())

Expand All @@ -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():
Expand Down Expand Up @@ -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():
Expand Down Expand Up @@ -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())

Expand Down