Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions tests/benchmark/test_filter_missing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import copy

import pytest

from globus_sdk.testing import get_response_set
from globus_sdk.transport.representation_providers import RequestsRepresentationProvider


@pytest.mark.parametrize(
("width", "depth"),
(
# note that the expected number of objects is roughly "WIDTH raised to DEPTH"
# so relatively modest numbers like 5x10 = 5 to the 10th = 9.7 million
# be careful to build wide-but-shallow or deep-but-narrow trees
pytest.param(1, 1, id="1w-1d"),
pytest.param(5, 1, id="5w-1d"),
pytest.param(1, 5, id="1w-5d"),
pytest.param(1, 1000, id="1w-1000d"),
pytest.param(5, 5, id="5w-5d"),
pytest.param(10, 5, id="10w-5d"),
),
)
def test_deeply_nested_object_encoding(benchmark, depth, width):
data = {}
for _ in range(depth):
data = {
# significant optimization: if we're building something really deep with
# width=1 we don't need to deepcopy
f"nested{i}": data if width == 1 else copy.deepcopy(data)
for i in range(width)
}

provider = RequestsRepresentationProvider()
method = "POST"
url = "https://example.api.globus.org/foo"
params = {}
headers = {}

benchmark(provider.encode, method, url, params, data, headers)


# Use known response objects as "typical" JSON blobs.
# These aren't a perfect representative sample, but they're more realistically similar
# to request data than fully synthetic object graphs.
@pytest.mark.parametrize(
"response_lookup_path",
(
"auth.get_consents",
"transfer.create_tunnel",
"flows.get_run_logs",
),
)
def test_typical_object_encoding(benchmark, response_lookup_path):
response_set = get_response_set(response_lookup_path)
data = response_set.lookup("default").json

provider = RequestsRepresentationProvider()
method = "POST"
url = "https://example.api.globus.org/foo"
params = {}
headers = {}

benchmark(provider.encode, method, url, params, data, headers)
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ commands =
deps =
-r requirements/py{py_dot_ver}/test.txt
pytest-benchmark
commands = pytest tests/benchmark/ {posargs}
commands = pytest {posargs:tests/benchmark/}

[testenv:pylint,pylint-{py3.9,py3.10,py3.11,py3.12,py3.13,py3.14}]
deps = pylint
Expand Down
Loading