Skip to content

Commit 84060dc

Browse files
committed
APP-6507: Optimized pagination tests by reducing API calls for faster execution
- Dynamically adjust page size based on total assets and expected number of API calls - Target ~5 API calls per test instead of many small calls - Improves test speed while still validating pagination logic
1 parent ff1dabc commit 84060dc

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

tests/integration/test_index_search.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# SPDX-License-Identifier: Apache-2.0
22
# Copyright 2022 Atlan Pte. Ltd.
3+
import math
34
from dataclasses import dataclass, field
45
from datetime import datetime
56
from time import sleep, time
@@ -335,8 +336,6 @@ def _assert_search_results(results, expected_sorts, size, TOTAL_ASSETS, bulk=Fal
335336

336337
@patch.object(LOGGER, "debug")
337338
def test_search_pagination(mock_logger, client: AtlanClient):
338-
size = 2
339-
340339
# Avoid testing on integration tests objects
341340
exclude_sdk_terms = [
342341
Asset.NAME.wildcard("psdk_*"),
@@ -352,13 +351,22 @@ def test_search_pagination(mock_logger, client: AtlanClient):
352351
dsl = DSL(
353352
query=query,
354353
post_filter=Term.with_type_name(value="AtlasGlossaryTerm"),
355-
size=size,
354+
size=0, # to get the total count
356355
)
356+
357357
request = IndexSearchRequest(dsl=dsl)
358358
results = client.asset.search(criteria=request)
359359
# Assigning this here to ensure the total assets
360360
# remain constant across different test cases
361361
TOTAL_ASSETS = results.count
362+
363+
# set page_size to divide into ~5 API calls
364+
size = max(1, math.ceil(TOTAL_ASSETS / 5))
365+
request.dsl.size = size
366+
367+
# Now, we can test different test scenarios for search() with the dynamic page size
368+
results = client.asset.search(criteria=request)
369+
362370
expected_sorts = [Asset.GUID.order(SortOrder.ASCENDING)]
363371
_assert_search_results(results, expected_sorts, size, TOTAL_ASSETS)
364372

@@ -385,7 +393,7 @@ def test_search_pagination(mock_logger, client: AtlanClient):
385393
FluentSearch(where_nots=exclude_sdk_terms)
386394
.where(CompoundQuery.active_assets())
387395
.where(CompoundQuery.asset_type(AtlasGlossaryTerm))
388-
.page_size(2)
396+
.page_size(size)
389397
).to_request()
390398
results = client.asset.search(criteria=request)
391399
expected_sorts = [Asset.GUID.order(SortOrder.ASCENDING)]
@@ -396,7 +404,7 @@ def test_search_pagination(mock_logger, client: AtlanClient):
396404
FluentSearch(where_nots=exclude_sdk_terms)
397405
.where(CompoundQuery.active_assets())
398406
.where(CompoundQuery.asset_type(AtlasGlossaryTerm))
399-
.page_size(2)
407+
.page_size(size)
400408
).to_request()
401409
results = client.asset.search(criteria=request, bulk=True)
402410
expected_sorts = [
@@ -413,7 +421,7 @@ def test_search_pagination(mock_logger, client: AtlanClient):
413421
FluentSearch(where_nots=exclude_sdk_terms)
414422
.where(CompoundQuery.active_assets())
415423
.where(CompoundQuery.asset_type(AtlasGlossaryTerm))
416-
.page_size(2)
424+
.page_size(size)
417425
).execute(client, bulk=True)
418426
expected_sorts = [
419427
Asset.CREATE_TIME.order(SortOrder.ASCENDING),
@@ -431,7 +439,7 @@ def test_search_pagination(mock_logger, client: AtlanClient):
431439
FluentSearch(where_nots=exclude_sdk_terms)
432440
.where(CompoundQuery.active_assets())
433441
.where(CompoundQuery.asset_type(AtlasGlossaryTerm))
434-
.page_size(2)
442+
.page_size(size)
435443
).to_request()
436444
results = client.asset.search(criteria=request)
437445
expected_sorts = [

0 commit comments

Comments
 (0)