Open Koshkaj opened 3 years ago
@long2ice Could you please have an input on this? is it a bug or could this be resolved ?
I'm not sure, but tortoise-orm is not related to websocket
I know that it is not related to the websocket in general, all I am saying is that the orm does not work with the websocket tests. Inside websockets I have a normal ORM which works fine on connections but obviously you have to write some unit tests for it right? Therefore when I tried to write unit tests it did not work and threw an error. Therefore the issue is in the implementation of a library.
Did you run Tortoise.init
on start of test?
Did you run
Tortoise.init
on start of test?
Yeah Obviously, I have it as an event when the app is initialized, thing is that HTTP API Endpoints and it's unit tests are working fine with the library, However the websocket unit tests are not working because it throws an exception which is mentioned above
I am regretting that I chose this library for the production, I literally cant write any tests because of this issue.
I would not recommend this library to anyone, It is not a production ready library at all.
I am regretting that I chose this library for the production, I literally cant write any tests because of this issue.
I would not recommend this library to anyone, It is not a production ready library at all.
- Ton of bugs
- Literally no one cares about the issues that are opened here daily
- Very poor and trivial documentation examples
I had the same exception ("different loop") using Tortoise and FastAPI. Tortoise and your _websocketapp must have the same event loop, Tortoise has a module for such integration (FastAPI), so I just had to create a fixture to instantiate the FastAPI app object and pass it to the _register_tortoise_ function.
@viniciusao Thanks for the reply, I have a different FastAPI instance for tests, and have a websocket as a different instance as well which is mounted to the main app and test app. therefore it should have a two different event loops. I can write ordinary API tests without any issues but when I try to connect to the websocket endpoint from the tests, this error is thrown that I described before. There is something wrong with the dynamic asynchronous db creation (asyncpg) and Tortoise's event loop, they come in conflict and thats why error is thrown
I have been wasting too much time to resolve that issue but I could not, I ended up writing tests in a base database in a CI/CD integration level and I manually remove garbage collect those data as soon as tests are finished so no worries.
Regardless, This library sucks lol
Describe the bug Whenever I try to connect to a websocket connection from pytest, and I try to run some queries in the database, it crashes and returns the following error
Traceback:
See my code below:
Obviously it has to do something with the event loop. It is a huge but since in a production environment I should be able to test websocket events without any issues but right now I cant even query something from the database before I connect to a websocket.