39 lines
920 B
Python
39 lines
920 B
Python
import pytest
|
|
from sqlalchemy.orm import Session
|
|
|
|
from dibbler.models import User
|
|
from dibbler.queries import user_balance
|
|
from tests.benchmark.helpers import generate_random_transactions, insert_users_and_products
|
|
|
|
|
|
@pytest.mark.benchmark(group='user_balance')
|
|
@pytest.mark.parametrize(
|
|
"transaction_count",
|
|
[
|
|
100,
|
|
500,
|
|
1000,
|
|
1500,
|
|
2000,
|
|
],
|
|
)
|
|
def test_benchmark_user_balance(benchmark, sql_session: Session, transaction_count: int):
|
|
users, _products = insert_users_and_products(sql_session)
|
|
|
|
generate_random_transactions(
|
|
sql_session,
|
|
transaction_count,
|
|
)
|
|
|
|
benchmark.pedantic(
|
|
query_all_users_balance,
|
|
args=(sql_session, users),
|
|
iterations=10,
|
|
rounds=5,
|
|
)
|
|
|
|
|
|
def query_all_users_balance(sql_session: Session, users: list[User]) -> None:
|
|
for user in users:
|
|
user_balance(sql_session, user)
|