You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am experimenting with ways to record and replay SQL queries send by asyncpg (similar to VCR.py).
I do not know the internals of asyncpg well and therefore would appreciate feedback and pointers.
To record and replay, following steps have to be done (roughly):
Record the SQL query and the results
Next time the same SQL query is executed, do not interact with the database at all (e.g. no connection and no execution). Instead, replay the recorded results.
Step 1
After reading the source code of asyncpg a bit, I decided to wrap the Connection._execute function like this:
(As context: Below record function is intended to be used as decorator around a test function.)
defrecord(func): @wraps(func)asyncdefwrapper(*args, **kwargs): execture_original=asyncpg.connection.Connection._execute@wraps(execture_original)asyncdefexecute_wrapper(self, *execute_args, **execute_kwargs): # TODO: Record (serialize to disk) execute parameters and resultreturnawaitexecture_original(self, *execute_args, **execute_kwargs) asyncpg.connection.Connection._execute=execute_wrapperreturnawaitfunc(*args, **kwargs) returnwrapper
Do you find this sensible? Any scenario where this approach would not work?
Step 2
Here I mainly have the following questions:
Which is the best way to mock every possible interaction with the database and create a asyncpg record object from the recorded results?
Any thoughts about any of the points above are highly appreciated. Thanks!
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I am experimenting with ways to record and replay SQL queries send by asyncpg (similar to VCR.py).
I do not know the internals of asyncpg well and therefore would appreciate feedback and pointers.
To record and replay, following steps have to be done (roughly):
Step 1
After reading the source code of asyncpg a bit, I decided to wrap the
Connection._execute
function like this:(As context: Below
record
function is intended to be used as decorator around a test function.)Do you find this sensible? Any scenario where this approach would not work?
Step 2
Here I mainly have the following questions:
Which is the best way to mock every possible interaction with the database and create a asyncpg record object from the recorded results?
Any thoughts about any of the points above are highly appreciated. Thanks!
Beta Was this translation helpful? Give feedback.
All reactions