Skip to content
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

fix bug where an edge case exception causes a query to not be removed… #88

Merged
merged 3 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
7 changes: 5 additions & 2 deletions sidecar/app/query/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,11 @@ def run_query(self, query: Query):
)

self.running_queries[query.query_id] = query
query.start()
del self.running_queries[query.query_id]
try:
query.start()
finally:
# always remove this
del self.running_queries[query.query_id]
eriktaubeneck marked this conversation as resolved.
Show resolved Hide resolved

@property
def capacity_available(self):
Expand Down
19 changes: 19 additions & 0 deletions sidecar/tests/app/query/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,22 @@ def fake_start():
) as mock_start:
query_manager.run_query(query)
mock_start.assert_called_once()


def test_query_manger_run_query_exception():
eriktaubeneck marked this conversation as resolved.
Show resolved Hide resolved
query_manager = QueryManager(max_parallel_queries=1)
query = Query(str(uuid4()))

def mock_exception():
raise Exception
eriktaubeneck marked this conversation as resolved.
Show resolved Hide resolved

with mock.patch(
"sidecar.app.query.base.Query.start", side_effect=mock_exception
) as mock_start:
with pytest.raises(Exception):
query_manager.run_query(query)

mock_start.assert_called_once()

assert query.query_id not in query_manager.running_queries
assert query_manager.capacity_available
Loading