BoostryJP / ibet-Wallet-API

A powerful API suite for seamlessly building ibet blockchain wallet systems 🛠
https://ibet.jp/ibet-for-fin
Apache License 2.0
9 stars 0 forks source link

[FEATURE] Reduce test data creation time in unit tests #1468

Closed purplesmoke05 closed 4 weeks ago

purplesmoke05 commented 10 months ago

Is your feature request related to a problem? Please describe.

Currently, our unit tests create test data on ganache (a blockchain simulator) by executing numerous blockchain requests before running test cases. These requests are executed sequentially, resulting in a significant amount of time being spent on test data creation.

Describe the solution you'd like

To reduce the time required for test data creation, inplement asynchronous execution of these requests.

purplesmoke05 commented 10 months ago

The web3 module caches and retains aiohttp.Client within it. (link) And the aiohttp.Client holds the running event loop as its private variable at the time of the object's creation. (link)

Additionally, pytest-asyncio uses different event loops at the session and function levels. https://pytest-asyncio.readthedocs.io/en/latest/concepts.html#asyncio-event-loops

Therefore, in pytest, if async_web3 is used at the session level and subsequently at the function level, the event loops do not match, leading to improper execution of requests.

To avoid this, it is necessary to delete cache of aiohttp.Client held by web3 in the function-level fixture.