Files
dibbler/tests/benchmark/test_benchmark_product_stock.py
2025-12-13 17:09:33 +09:00

48 lines
1.3 KiB
Python

import pytest
from sqlalchemy.orm import Session
from dibbler.models import Product, TransactionType
from dibbler.queries import product_stock
from tests.benchmark.benchmark_settings import BENCHMARK_ITERATIONS, BENCHMARK_ROUNDS
from tests.benchmark.helpers import generate_random_transactions, insert_users_and_products
@pytest.mark.benchmark(group='product_stock')
@pytest.mark.parametrize(
"transaction_count",
[
100,
500,
1000,
2000,
5000,
10000,
],
)
def test_benchmark_product_stock(benchmark, sql_session: Session, transaction_count: int):
_users, products = insert_users_and_products(sql_session)
generate_random_transactions(
sql_session,
transaction_count,
transaction_type_filter=[
TransactionType.ADD_PRODUCT,
TransactionType.ADJUST_STOCK,
TransactionType.BUY_PRODUCT,
TransactionType.JOINT,
TransactionType.THROW_PRODUCT,
],
)
benchmark.pedantic(
query_all_products_stock,
args=(sql_session, products),
iterations=BENCHMARK_ITERATIONS,
rounds=BENCHMARK_ROUNDS,
)
def query_all_products_stock(sql_session: Session, products: list[Product]) -> None:
for product in products:
product_stock(sql_session, product)