Skip to content

Commit dac1a5d

Browse files
committed
address coderabbit review
Signed-off-by: Jordan Dubrick <jdubrick@redhat.com>
1 parent d9c416e commit dac1a5d

1 file changed

Lines changed: 17 additions & 5 deletions

File tree

tests/unit/app/endpoints/test_feedback.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,16 @@
2727
from tests.unit.utils.auth_helpers import mock_authorization_resolvers
2828

2929
MOCK_AUTH = ("mock_user_id", "mock_username", False, "mock_token")
30+
31+
32+
@pytest.fixture(autouse=True)
33+
def _reset_feedback_config():
34+
"""Save and restore feedback configuration so tests don't leak state."""
35+
original_enabled = configuration.user_data_collection_configuration.feedback_enabled
36+
original_storage = configuration.user_data_collection_configuration.feedback_storage
37+
yield
38+
configuration.user_data_collection_configuration.feedback_enabled = original_enabled
39+
configuration.user_data_collection_configuration.feedback_storage = original_storage
3040
VALID_BASE = {
3141
"conversation_id": "12345678-abcd-0000-0123-456789abcdef",
3242
"user_question": "What is Kubernetes?",
@@ -383,24 +393,26 @@ def test_update_feedback_status_concurrent(mocker: MockerFixture) -> None:
383393
configuration.user_data_collection_configuration.feedback_enabled = True
384394

385395
auth: AuthTuple = ("test_user_id", "test_user", True, "test_token")
386-
results: list[Any] = [None, None, None]
387-
errors: list[Exception | None] = [None, None, None]
396+
thread_args = [(0, False), (1, True), (2, False)]
397+
results: list[Any] = [None] * len(thread_args)
398+
errors: list[Exception | None] = [None] * len(thread_args)
399+
barrier = threading.Barrier(len(thread_args) + 1)
388400

389401
def worker(index: int, desired_status: bool) -> None:
390402
"""Thread worker that calls update_feedback_status."""
391403
req = FeedbackStatusUpdateRequest(status=desired_status)
392404
try:
405+
barrier.wait()
393406
results[index] = asyncio.run(update_feedback_status(req, auth=auth))
394407
except Exception as exc: # pylint: disable=broad-exception-caught
395408
errors[index] = exc
396409

397410
threads = [
398-
threading.Thread(target=worker, args=(0, False)),
399-
threading.Thread(target=worker, args=(1, True)),
400-
threading.Thread(target=worker, args=(2, False)),
411+
threading.Thread(target=worker, args=args) for args in thread_args
401412
]
402413
for t in threads:
403414
t.start()
415+
barrier.wait()
404416
for t in threads:
405417
t.join()
406418

0 commit comments

Comments
 (0)