-
Notifications
You must be signed in to change notification settings - Fork 46
fix(file-based): respect _concurrency_level for thread pool sizing #1035
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
devin-ai-integration
wants to merge
2
commits into
main
Choose a base branch
from
devin/1779723955-fix-file-based-concurrency-level
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
unit_tests/sources/file_based/test_file_based_source_concurrency.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| # | ||
| # Copyright (c) 2026 Airbyte, Inc., all rights reserved. | ||
| # | ||
|
|
||
| from unittest.mock import MagicMock, patch | ||
|
|
||
| import pytest | ||
|
|
||
| from airbyte_cdk.sources.file_based.file_based_source import ( | ||
| DEFAULT_CONCURRENCY, | ||
| MAX_CONCURRENCY, | ||
| FileBasedSource, | ||
| ) | ||
|
|
||
|
|
||
| class _ConcreteFBSource(FileBasedSource): | ||
| """Minimal concrete subclass so we can instantiate FileBasedSource.""" | ||
|
|
||
| _concurrency_level = None | ||
|
|
||
| @property | ||
| def name(self) -> str: | ||
| return "test-source" | ||
|
|
||
| def check_connection(self, logger, config): | ||
| return True, None | ||
|
|
||
| def streams(self, config): | ||
| return [] | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "concurrency_level, expected_num_workers, expected_initial_partitions", | ||
| [ | ||
| pytest.param(None, MAX_CONCURRENCY, MAX_CONCURRENCY // 2, id="none_uses_max"), | ||
| pytest.param(100, 100, 50, id="default_concurrency"), | ||
| pytest.param(20, 20, 10, id="reduced_concurrency"), | ||
| pytest.param(2, 2, 1, id="minimal_concurrency"), | ||
| pytest.param(200, MAX_CONCURRENCY, MAX_CONCURRENCY // 2, id="capped_at_max"), | ||
| ], | ||
| ) | ||
| def test_concurrency_level_controls_thread_pool_size( | ||
| concurrency_level, expected_num_workers, expected_initial_partitions | ||
| ): | ||
| _ConcreteFBSource._concurrency_level = concurrency_level | ||
|
|
||
| with patch( | ||
| "airbyte_cdk.sources.file_based.file_based_source.ConcurrentSource.create" | ||
| ) as mock_create: | ||
| mock_create.return_value = MagicMock() | ||
| try: | ||
| _ConcreteFBSource( | ||
| stream_reader=MagicMock(), | ||
| spec_class=MagicMock(), | ||
| catalog=None, | ||
| config=None, | ||
| state=None, | ||
| ) | ||
| except Exception: | ||
| pass # Other init errors are fine; we only care about the ConcurrentSource.create call | ||
|
|
||
| mock_create.assert_called_once() | ||
| call_args = mock_create.call_args | ||
| actual_num_workers = call_args[0][0] | ||
| actual_initial_partitions = call_args[0][1] | ||
| assert actual_num_workers == expected_num_workers | ||
| assert actual_initial_partitions == expected_initial_partitions | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.