Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

if both has the same timestamp AIOHttpConnection shouldn't raise error #164

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
7 changes: 7 additions & 0 deletions aioelasticsearch/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
19 changes: 19 additions & 0 deletions tests/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()))