Skip to content

chore(ci): refactor thread safe tests #6889

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

Merged
merged 2 commits into from
Jun 30, 2025
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import random
import re
import string
import sys
import time
from collections import namedtuple
from threading import Thread
Expand Down Expand Up @@ -418,7 +417,6 @@ def handler(event, context):
assert "stack_trace" not in log


@pytest.mark.skipif(reason="Test temporarily disabled")
def test_thread_safe_keys_encapsulation(service_name, stdout):
logger = Logger(
service=service_name,
Expand All @@ -434,9 +432,16 @@ def send_thread_message_with_key(message, keys):
logger.info("global key added")

thread1_keys = {"exampleThread1Key": "thread1"}
Thread(target=send_thread_message_with_key, args=("thread1", thread1_keys)).start()
thread1 = Thread(target=send_thread_message_with_key, args=("thread1", thread1_keys))

thread1.start()
thread1.join()

thread2_keys = {"exampleThread2Key": "thread2"}
Thread(target=send_thread_message_with_key, args=("thread2", thread2_keys)).start()
thread2 = Thread(target=send_thread_message_with_key, args=("thread2", thread2_keys))

thread2.start()
thread2.join()

logger.info("final log, all thread keys gone")

Expand All @@ -457,7 +462,6 @@ def send_thread_message_with_key(message, keys):
assert logs[3].get("exampleThread2Key") is None


@pytest.mark.skipif(sys.version_info >= (3, 13), reason="Test temporarily disabled for Python 3.13+")
def test_thread_safe_remove_key(service_name, stdout):
logger = Logger(
service=service_name,
Expand All @@ -471,10 +475,12 @@ def send_message_with_key_and_without(message, keys):
logger.info(message)

thread1_keys = {"exampleThread1Key": "thread1"}
Thread(target=send_message_with_key_and_without, args=("msg", thread1_keys)).start()
thread1 = Thread(target=send_message_with_key_and_without, args=("msg", thread1_keys))

thread1.start()
thread1.join()

logs = capture_logging_output(stdout)
print(logs)

assert logs[0].get("exampleThread1Key") == "thread1"
assert logs[1].get("exampleThread1Key") is None
Expand All @@ -493,10 +499,12 @@ def send_message_with_key_and_clear(message, keys):
logger.info(message)

thread1_keys = {"exampleThread1Key": "thread1"}
Thread(target=send_message_with_key_and_clear, args=("msg", thread1_keys)).start()
thread1 = Thread(target=send_message_with_key_and_clear, args=("msg", thread1_keys))

thread1.start()
thread1.join()

logs = capture_logging_output(stdout)
print(logs)

assert logs[0].get("exampleThread1Key") == "thread1"
assert logs[1].get("exampleThread1Key") is None
Expand All @@ -513,10 +521,12 @@ def send_message_with_key_and_get(message, keys):
logger.info(logger.thread_safe_get_current_keys())

thread1_keys = {"exampleThread1Key": "thread1"}
Thread(target=send_message_with_key_and_get, args=("msg", thread1_keys)).start()
thread1 = Thread(target=send_message_with_key_and_get, args=("msg", thread1_keys))

thread1.start()
thread1.join()

logs = capture_logging_output(stdout)
print(logs)

assert logs[0].get("exampleThread1Key") == "thread1"
assert logs[0].get("message") == thread1_keys
Loading