Skip to content

Cleaning up sessions after each test #11

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

Merged
merged 1 commit into from
Aug 24, 2024
Merged
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
1 change: 0 additions & 1 deletion arangoasync/connection.py
Original file line number Diff line number Diff line change
@@ -81,7 +81,6 @@ async def process_request(self, request: Request) -> Response:
ConnectionAbortedError: If can't connect to host(s) within limit.
"""

ex_host_index = -1
host_index = self._host_resolver.get_host_index()
for tries in range(self._host_resolver.max_tries):
try:
16 changes: 16 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from dataclasses import dataclass

import pytest
import pytest_asyncio


@dataclass
@@ -57,3 +58,18 @@ def password():
@pytest.fixture(autouse=False)
def sys_db_name():
return global_data.sys_db_name


@pytest_asyncio.fixture
async def client_session():
sessions = []

def get_client_session(client, url):
s = client.create_session(url)
sessions.append(s)
return s

yield get_client_session

for session in sessions:
await session.close()
12 changes: 6 additions & 6 deletions tests/test_connection.py
Original file line number Diff line number Diff line change
@@ -8,9 +8,9 @@


@pytest.mark.asyncio
async def test_BasicConnection_ping_failed(url, sys_db_name):
async def test_BasicConnection_ping_failed(client_session, url, sys_db_name):
client = AioHTTPClient()
session = client.create_session(url)
session = client_session(client, url)
resolver = DefaultHostResolver(1)

connection = BasicConnection(
@@ -22,13 +22,14 @@ async def test_BasicConnection_ping_failed(url, sys_db_name):

with pytest.raises(ServerConnectionError):
await connection.ping()
await session.close()


@pytest.mark.asyncio
async def test_BasicConnection_ping_success(url, sys_db_name, root, password):
async def test_BasicConnection_ping_success(
client_session, url, sys_db_name, root, password
):
client = AioHTTPClient()
session = client.create_session(url)
session = client_session(client, url)
resolver = DefaultHostResolver(1)

connection = BasicConnection(
@@ -41,4 +42,3 @@ async def test_BasicConnection_ping_success(url, sys_db_name, root, password):

status_code = await connection.ping()
assert status_code == 200
await session.close()
15 changes: 6 additions & 9 deletions tests/test_http.py
Original file line number Diff line number Diff line change
@@ -13,22 +13,21 @@ def test_DefaultHTTPClient():


@pytest.mark.asyncio
async def test_AioHTTPClient_wrong_url():
async def test_AioHTTPClient_wrong_url(client_session):
client = AioHTTPClient()
session = client.create_session("http://www.fasdfdsafadawe3523523532plmcom.tgzs")
session = client_session(client, "http://localhost:0000")
request = Request(
method=Method.GET,
endpoint="/_api/version",
)
with pytest.raises(ClientConnectionError):
await client.send_request(session, request)
await session.close()


@pytest.mark.asyncio
async def test_AioHTTPClient_simple_request(url):
async def test_AioHTTPClient_simple_request(client_session, url):
client = AioHTTPClient()
session = client.create_session(url)
session = client_session(client, url)
request = Request(
method=Method.GET,
endpoint="/_api/version",
@@ -38,13 +37,12 @@ async def test_AioHTTPClient_simple_request(url):
assert response.url == f"{url}/_api/version"
assert response.status_code == 401
assert response.status_text == "Unauthorized"
await session.close()


@pytest.mark.asyncio
async def test_AioHTTPClient_auth_pass(url, root, password):
async def test_AioHTTPClient_auth_pass(client_session, url, root, password):
client = AioHTTPClient()
session = client.create_session(url)
session = client_session(client, url)
request = Request(
method=Method.GET,
endpoint="/_api/version",
@@ -55,4 +53,3 @@ async def test_AioHTTPClient_auth_pass(url, root, password):
assert response.url == f"{url}/_api/version"
assert response.status_code == 200
assert response.status_text == "OK"
await session.close()