From 09f7cd39736e3b9189c7329cebef04b5c631db9d Mon Sep 17 00:00:00 2001 From: svalee Date: Sat, 20 Apr 2019 18:07:09 +0300 Subject: [PATCH] if both has the same timestamp AIOHttpConnection shouldn't raise error --- aioelasticsearch/connection.py | 7 +++++++ tests/test_connection.py | 19 +++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/aioelasticsearch/connection.py b/aioelasticsearch/connection.py index 1c19c774..b1210aa7 100644 --- a/aioelasticsearch/connection.py +++ b/aioelasticsearch/connection.py @@ -76,6 +76,13 @@ def __init__( ), ) + def __eq__(self, other): + if not isinstance(other, AIOHttpConnection): + raise TypeError( + "Unsupported equality check for %s and %s" % (self, other) + ) + return True + async def close(self): await self.session.close() diff --git a/tests/test_connection.py b/tests/test_connection.py index 28942598..9930ce92 100644 --- a/tests/test_connection.py +++ b/tests/test_connection.py @@ -85,3 +85,22 @@ async def coro(*args, **Kwargs): use_ssl=True)) with pytest.raises(expected): await conn.perform_request('HEAD', '/') + + +@pytest.mark.run_loop +async def test_priority_queue_same_timestamp(auto_close, loop): + conn = auto_close(AIOHttpConnection(http_auth='user:pass', loop=loop)) + conn2 = auto_close(AIOHttpConnection(http_auth='user:pass', loop=loop)) + queue = asyncio.PriorityQueue(10, loop=loop) + time = loop.time() + + # not raising error if both AIOHttpConnectionPool + queue.put_nowait( + (time, conn) + ) + queue.put_nowait( + (time, conn2) + ) + + with pytest.raises(TypeError): + queue.put_nowait((time, object()))