Skip to content

Commit

Permalink
Merge pull request #111 from evo-company/add-endpoint-benches
Browse files Browse the repository at this point in the history
add endpoint benches
  • Loading branch information
kindermax committed Jul 18, 2023
2 parents 08d5397 + 7d02680 commit 6eea610
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ examples = [
importlib-metadata = ">=4.3"

[tool.pdm.scripts]
bench = "python -m pytest --benchmark-enable {args:tests}"
test = "python -m pytest {args:tests}"
test-pg = "python -m pytest {args:tests_pg}"
test-pg-local = "python -m pytest --pg-host=localhost {args:tests_pg}"
Expand Down
60 changes: 60 additions & 0 deletions tests/benchmarks/test_endpoint.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import pytest

from hiku.graph import Graph, Root, Field
from hiku.types import String

from hiku.engine import Engine
from hiku.executors.sync import SyncExecutor
from hiku.endpoint.graphql import GraphQLEndpoint

from hiku.federation.endpoint import FederatedGraphQLEndpoint
from hiku.federation.engine import Engine as FederatedEngine
from hiku.federation.graph import Graph as FederatedGraph


@pytest.fixture(name="graph")
def graph_fixture():
def answer(fields):
return ["42" for _ in fields]

return Graph([Root([Field("answer", String, answer)])])


@pytest.fixture(name="endpoint")
def endpoint_fixture(graph):
return GraphQLEndpoint(Engine(SyncExecutor()), graph)


@pytest.fixture(name="federated_graph")
def federated_graph_fixture():
def answer(fields):
return ["42" for _ in fields]

return FederatedGraph([Root([Field("answer", String, answer)])])


@pytest.fixture(name="federated_endpoint")
def federated_endpoint_fixture(federated_graph):
return FederatedGraphQLEndpoint(
FederatedEngine(SyncExecutor()),
federated_graph
)


def test_federated_endpoint(benchmark, federated_endpoint):
result = benchmark.pedantic(
federated_endpoint.dispatch, args=({"query": "{answer}"},),
iterations=5,
rounds=1000
)
assert result == {"data": {"answer": "42"}}


def test_endpoint(benchmark, endpoint):
result = benchmark.pedantic(
endpoint.dispatch, args=({"query": "{answer}"},),
iterations=5,
rounds=1000
)

assert result == {"data": {"answer": "42"}}

0 comments on commit 6eea610

Please sign in to comment.