@@ -174,24 +174,36 @@ def target():
174174 assert t .run .__qualname__ == original_run .__qualname__
175175
176176
177- def test_scope_data_not_leaked_in_threads (sentry_init ):
177+ @pytest .mark .parametrize (
178+ "propagate_scope" ,
179+ (True , False ),
180+ ids = ["propagate_scope=True" , "propagate_scope=False" ],
181+ )
182+ def test_scope_data_not_leaked_in_threads (sentry_init , propagate_scope ):
178183 sentry_init (
179- integrations = [ThreadingIntegration ()],
184+ integrations = [ThreadingIntegration (propagate_scope = propagate_scope )],
180185 )
181186
182187 sentry_sdk .set_tag ("initial_tag" , "initial_value" )
183188 initial_iso_scope = sentry_sdk .get_isolation_scope ()
184189
185- def do_some_work (number ):
190+ def do_some_work ():
191+ # check if we have the initial scope data propagated into the thread
192+ if propagate_scope :
193+ assert sentry_sdk .get_isolation_scope ()._tags == {
194+ "initial_tag" : "initial_value"
195+ }
196+ else :
197+ assert sentry_sdk .get_isolation_scope ()._tags == {}
198+
186199 # change data in isolation scope in thread
187200 sentry_sdk .set_tag ("thread_tag" , "thread_value" )
188201
189- with futures .ThreadPoolExecutor (max_workers = 2 ) as executor :
190- all_futures = []
191- for number in range (10 ):
192- all_futures .append (executor .submit (do_some_work , number ))
193- futures .wait (all_futures )
202+ t = Thread (target = do_some_work )
203+ t .start ()
204+ t .join ()
194205
206+ # check if the initial scope data is not modified by the started thread
195207 assert initial_iso_scope ._tags == {
196208 "initial_tag" : "initial_value"
197- }, "The isolation scope in the main thread should not be modified by the started threads ."
209+ }, "The isolation scope in the main thread should not be modified by the started thread ."
0 commit comments