@@ -23,22 +23,24 @@ def setUp(self) -> None:
2323
2424 def test_get_transactions_for_project (self ) -> None :
2525 """Test the full end-to-end happy path for get_transactions_for_project."""
26- # Create spans for different transactions with varying volumes
26+ # Create spans for different transactions with varying total time spent
27+ # Format: (transaction_name, count, avg_duration_ms)
2728 transactions_data = [
28- ("api/users/profile" , 5 ), # High volume
29- ("api/posts/create" , 3 ), # Medium volume
30- ("api/health" , 1 ), # Low volume
29+ ("api/users/profile" , 5 , 100.0 ), # 5 * 100 = 500ms total (highest)
30+ ("api/posts/create" , 3 , 150.0 ), # 3 * 150 = 450ms total (middle)
31+ ("api/health" , 10 , 10.0 ), # 10 * 10 = 100ms total (lowest, despite high count)
3132 ]
3233
33- # Store transaction spans with different volumes
34+ # Store transaction spans with different volumes and durations
3435 spans = []
35- for transaction_name , count in transactions_data :
36+ for transaction_name , count , duration_ms in transactions_data :
3637 for i in range (count ):
3738 span = self .create_span (
3839 {
3940 "description" : f"transaction-span-{ i } " ,
4041 "sentry_tags" : {"transaction" : transaction_name },
4142 "is_segment" : True , # This marks it as a transaction span
43+ "duration_ms" : duration_ms ,
4244 },
4345 start_ts = self .ten_mins_ago + timedelta (minutes = i ),
4446 )
@@ -51,6 +53,7 @@ def test_get_transactions_for_project(self) -> None:
5153 "description" : f"regular-span-{ i } " ,
5254 "sentry_tags" : {"transaction" : transaction_name },
5355 "is_segment" : False , # This marks it as a regular span
56+ "duration_ms" : 50.0 ,
5457 },
5558 start_ts = self .ten_mins_ago + timedelta (minutes = i , seconds = 30 ),
5659 )
@@ -64,11 +67,11 @@ def test_get_transactions_for_project(self) -> None:
6467 # Verify basic structure and data
6568 assert len (result ) == 3
6669
67- # Should be sorted by volume (count) descending - only transaction spans count
70+ # Should be sorted by total time spent (sum of duration) descending
6871 transaction_names = [t .name for t in result ]
69- assert transaction_names [0 ] == "api/users/profile" # Highest count (5 transaction spans )
70- assert transaction_names [1 ] == "api/posts/create" # Medium count (3 transaction spans )
71- assert transaction_names [2 ] == "api/health" # Lowest count (1 transaction span )
72+ assert transaction_names [0 ] == "api/users/profile" # 500ms total (highest )
73+ assert transaction_names [1 ] == "api/posts/create" # 450ms total (middle )
74+ assert transaction_names [2 ] == "api/health" # 100ms total (lowest despite high count )
7275
7376 # Verify all transactions have correct project_id and structure
7477 for transaction in result :
0 commit comments