|
2 | 2 |
|
3 | 3 | import pytest |
4 | 4 |
|
5 | | -from sentry.grouping.api import load_grouping_config |
6 | | -from sentry.grouping.component import ( |
7 | | - StacktraceGroupingComponent, |
8 | | - ThreadNameGroupingComponent, |
9 | | - ThreadsGroupingComponent, |
10 | | -) |
| 5 | +from sentry.grouping.component import StacktraceGroupingComponent |
11 | 6 | from sentry.grouping.strategies.base import GroupingContext, create_strategy_configuration_class |
12 | 7 | from sentry.services.eventstore.models import Event |
13 | 8 | from sentry.testutils.cases import TestCase |
@@ -304,162 +299,3 @@ def test_stacktrace_contribution_values_no_contributing_frames(self) -> None: |
304 | 299 | assert ( |
305 | 300 | system_stacktrace_component.hint == "ignored because it contains no contributing frames" |
306 | 301 | ) |
307 | | - |
308 | | - |
309 | | -class ThreadGroupingTest(TestCase): |
310 | | - """Tests for thread metadata in automatic grouping""" |
311 | | - |
312 | | - def test_thread_name_grouping_enabled(self) -> None: |
313 | | - """Test that thread name contributes to grouping when enabled""" |
314 | | - # Create two events with same stacktrace but different thread names |
315 | | - # Use threads-only (no exception) to test thread grouping |
316 | | - event_main_thread = save_new_event( |
317 | | - { |
318 | | - "threads": { |
319 | | - "values": [ |
320 | | - { |
321 | | - "id": "1", |
322 | | - "name": "MainThread", |
323 | | - "crashed": True, |
324 | | - "current": False, |
325 | | - "stacktrace": { |
326 | | - "frames": [ |
327 | | - {"function": "query", "module": "app.db", "in_app": True} |
328 | | - ] |
329 | | - }, |
330 | | - } |
331 | | - ] |
332 | | - }, |
333 | | - }, |
334 | | - self.project, |
335 | | - ) |
336 | | - |
337 | | - event_worker_thread = save_new_event( |
338 | | - { |
339 | | - "threads": { |
340 | | - "values": [ |
341 | | - { |
342 | | - "id": "2", |
343 | | - "name": "WorkerThread", |
344 | | - "crashed": True, |
345 | | - "current": False, |
346 | | - "stacktrace": { |
347 | | - "frames": [ |
348 | | - {"function": "query", "module": "app.db", "in_app": True} |
349 | | - ] |
350 | | - }, |
351 | | - } |
352 | | - ] |
353 | | - }, |
354 | | - }, |
355 | | - self.project, |
356 | | - ) |
357 | | - |
358 | | - # With thread name grouping enabled |
359 | | - config_with_threads = load_grouping_config( |
360 | | - {"id": "newstyle:2025-with-threads", "enhancements": None} |
361 | | - ) |
362 | | - |
363 | | - variants_main = event_main_thread.get_grouping_variants(force_config=config_with_threads) |
364 | | - variants_worker = event_worker_thread.get_grouping_variants( |
365 | | - force_config=config_with_threads |
366 | | - ) |
367 | | - |
368 | | - # They should have different hashes because thread names differ |
369 | | - assert variants_main["app"].get_hash() is not None, "Main thread variant should have a hash" |
370 | | - assert ( |
371 | | - variants_worker["app"].get_hash() is not None |
372 | | - ), "Worker thread variant should have a hash" |
373 | | - assert ( |
374 | | - variants_main["app"].get_hash() != variants_worker["app"].get_hash() |
375 | | - ), "Different thread names should produce different hashes" |
376 | | - |
377 | | - def test_thread_name_grouping_disabled(self) -> None: |
378 | | - """Test that without thread grouping, threads don't affect grouping""" |
379 | | - event_main_thread = save_new_event( |
380 | | - { |
381 | | - "threads": { |
382 | | - "values": [ |
383 | | - { |
384 | | - "id": "1", |
385 | | - "name": "MainThread", |
386 | | - "crashed": True, |
387 | | - "stacktrace": { |
388 | | - "frames": [ |
389 | | - {"function": "query", "module": "app.db", "in_app": True} |
390 | | - ] |
391 | | - }, |
392 | | - } |
393 | | - ] |
394 | | - }, |
395 | | - }, |
396 | | - self.project, |
397 | | - ) |
398 | | - |
399 | | - event_worker_thread = save_new_event( |
400 | | - { |
401 | | - "threads": { |
402 | | - "values": [ |
403 | | - { |
404 | | - "id": "2", |
405 | | - "name": "WorkerThread", |
406 | | - "crashed": True, |
407 | | - "stacktrace": { |
408 | | - "frames": [ |
409 | | - {"function": "query", "module": "app.db", "in_app": True} |
410 | | - ] |
411 | | - }, |
412 | | - } |
413 | | - ] |
414 | | - }, |
415 | | - }, |
416 | | - self.project, |
417 | | - ) |
418 | | - |
419 | | - # Default config without thread grouping |
420 | | - config_default = load_grouping_config({"id": "newstyle:2023-01-11", "enhancements": None}) |
421 | | - |
422 | | - variants_main = event_main_thread.get_grouping_variants(force_config=config_default) |
423 | | - variants_worker = event_worker_thread.get_grouping_variants(force_config=config_default) |
424 | | - |
425 | | - # They should have the same hash - thread name doesn't matter without the config |
426 | | - assert variants_main["app"].get_hash() == variants_worker["app"].get_hash() |
427 | | - |
428 | | - def test_thread_metadata_component_structure(self) -> None: |
429 | | - """Test that thread metadata components are structured correctly""" |
430 | | - event = save_new_event( |
431 | | - { |
432 | | - "threads": { |
433 | | - "values": [ |
434 | | - { |
435 | | - "name": "MainThread", |
436 | | - "crashed": True, |
437 | | - "stacktrace": {"frames": [{"function": "main", "in_app": True}]}, |
438 | | - } |
439 | | - ] |
440 | | - }, |
441 | | - }, |
442 | | - self.project, |
443 | | - ) |
444 | | - |
445 | | - config = load_grouping_config({"id": "newstyle:2025-with-threads", "enhancements": None}) |
446 | | - |
447 | | - variants = event.get_grouping_variants(force_config=config) |
448 | | - threads_component = variants["app"].contributing_component |
449 | | - |
450 | | - # The contributing component should be a ThreadsGroupingComponent |
451 | | - assert isinstance(threads_component, ThreadsGroupingComponent) |
452 | | - |
453 | | - # Check that thread metadata is accessible |
454 | | - assert len(threads_component.metadata) > 0, "Thread metadata should be present" |
455 | | - |
456 | | - # Find the ThreadNameGroupingComponent in metadata |
457 | | - thread_name_component = next( |
458 | | - (m for m in threads_component.metadata if isinstance(m, ThreadNameGroupingComponent)), |
459 | | - None, |
460 | | - ) |
461 | | - assert ( |
462 | | - thread_name_component is not None |
463 | | - ), "ThreadNameGroupingComponent not found in metadata" |
464 | | - assert thread_name_component.values == ["MainThread"] |
465 | | - assert thread_name_component.contributes is True |
0 commit comments