atlassian / atlassian/asap-authentication-python

HTTPSPublicKeyRetriever caches asyncio event loop - pytest-asyncio issues

Aperta
#143 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
Python
Stelle
26
Fork
19
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

Hey there. I'm using `atlassian_jwt_auth` in an ayncio context; specifically using [pytest-asyncio](https://pypi.org/project/pytest-asyncio/) for the event loop creation. By default this library creates a new event loop for each test. (This is my desired behavior.)

However when running two tests that both utilize the HTTPSPublicKeyRetriever, the second test fails because the cached `HTTPSPublicKeyRetriever._class_session` is used with a now-shutdown event loop.

I've gotten around this with a fixture like so:

```python
@pytest.fixture(autouse=True)
async def clean_https_session():
yield
await HTTPSPublicKeyRetriever._class_session.close()
HTTPSPublicKeyRetriever._class_session = None
```

However this feels sort of wacky. Ideally I'd like the library to detect this and invalidate the _class_session either when the loop is shut down or when the session is gotten.

Adding a conditional [here](https://github.com/atlassian/asap-authentication-python/blob/master/atlassian_jwt_auth/contrib/aiohttp/key.py#L23-L26) of `client.loop != self.loop` fixes the issue, but `client.loop` is [deprecated in aiohttp](https://github.com/aio-libs/aiohttp/blob/v3.7.4.post0/aiohttp/client.py#L995-L1001) and actually has been removed in the newest master branch.

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Direzione di ricerca

Inizia in atlassian_jwt_auth/contrib/aiohttp/key.py, nella gestione della sessione di HTTPSPublicKeyRetriever, quindi riproduci il problema con due test pytest-asyncio che usano event loop separati. Determina come invalidare il _class_session memorizzato nella cache senza dipendere dall’attributo deprecato client.loop; il lavoro è completato quando entrambi i test terminano senza riutilizzare una sessione associata a un loop chiuso.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python
Ambito
authentication
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
55/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.