-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from aioworkers/#12_extra_parameters_pool
#12 extra parameters pool
- Loading branch information
Showing
7 changed files
with
147 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import pytest | ||
from aioworkers.utils import import_uri | ||
from asyncpg.connection import Connection | ||
from asyncpg.protocol.protocol import Record | ||
|
||
|
||
class CustomConnection(Connection): | ||
async def execute(self, query: str, *args, timeout: float = None) -> str: | ||
query += "SELECT 1" | ||
return await super().execute(query, *args, timeout=timeout) | ||
|
||
|
||
class CustomRecord(Record): | ||
pass | ||
|
||
|
||
@pytest.fixture | ||
def config(config, dsn): | ||
config.update( | ||
db={ | ||
"cls": "aioworkers_pg.base.Connector", | ||
"dsn": dsn, | ||
"pool": { | ||
"connection_class": import_uri(CustomConnection), | ||
"record_class": import_uri(CustomRecord), | ||
}, | ||
}, | ||
) | ||
return config | ||
|
||
|
||
async def test_custom_classes(context): | ||
# Run an empty query. The final query will be updated in the CustomConnection. | ||
await context.db.execute("") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import pytest | ||
|
||
|
||
@pytest.fixture | ||
def config(config, dsn): | ||
config.update( | ||
db={ | ||
"cls": "aioworkers_pg.base.Connector", | ||
"dsn": dsn, | ||
"pool": { | ||
"min_size": 1, | ||
"max_size": 1, | ||
}, | ||
}, | ||
) | ||
return config | ||
|
||
|
||
async def test_custom_pool_setup(context): | ||
assert context.db._pool._minsize == 1 | ||
assert context.db._pool._maxsize == 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import pytest | ||
from aioworkers.utils import import_uri | ||
|
||
|
||
async def custom_setup(connection): | ||
pass | ||
|
||
|
||
@pytest.fixture | ||
def config(config, dsn): | ||
config.update( | ||
db={ | ||
"cls": "aioworkers_pg.base.Connector", | ||
"dsn": dsn, | ||
"pool": { | ||
"setup": import_uri(custom_setup), | ||
}, | ||
}, | ||
) | ||
return config | ||
|
||
|
||
async def test_custom_pool_setup(context): | ||
await context.db.execute("SELECT 1") |