@@ -260,7 +260,7 @@ class TestException(Exception):
260
260
def __init__ (self , message ):
261
261
super (TestException , self ).__init__ (message )
262
262
263
- segment = Segment ('test' )
263
+ segment_one = Segment ('test' )
264
264
265
265
stack_one = [
266
266
('/path/to/test.py' , 10 , 'module' , 'another_function()' ),
@@ -275,18 +275,18 @@ def __init__(self, message):
275
275
exception_one = TestException ('test message one' )
276
276
exception_two = TestException ('test message two' )
277
277
278
- segment .add_exception (exception_one , stack_one , True )
279
- segment .add_exception (exception_two , stack_two , False )
278
+ segment_one .add_exception (exception_one , stack_one , True )
279
+ segment_one .add_exception (exception_two , stack_two , False )
280
280
281
- segment .close ()
281
+ segment_one .close ()
282
282
283
- expected_segment_dict = {
284
- "id" : segment .id ,
283
+ expected_segment_one_dict = {
284
+ "id" : segment_one .id ,
285
285
"name" : "test" ,
286
- "start_time" : segment .start_time ,
286
+ "start_time" : segment_one .start_time ,
287
287
"in_progress" : False ,
288
288
"cause" : {
289
- "working_directory" : segment .cause ['working_directory' ],
289
+ "working_directory" : segment_one .cause ['working_directory' ],
290
290
"exceptions" : [
291
291
{
292
292
"id" : exception_one ._cause_id ,
@@ -326,14 +326,39 @@ def __init__(self, message):
326
326
}
327
327
]
328
328
},
329
- "trace_id" : segment .trace_id ,
329
+ "trace_id" : segment_one .trace_id ,
330
330
"fault" : True ,
331
- "end_time" : segment .end_time
331
+ "end_time" : segment_one .end_time
332
332
}
333
333
334
- actual_segment_dict = entity_to_dict (segment )
334
+ segment_two = Segment ('test' )
335
+ subsegment = Subsegment ('test' , 'local' , segment_two )
336
+
337
+ subsegment .add_exception (exception_one , stack_one , True )
338
+ subsegment .add_exception (exception_two , stack_two , False )
339
+ subsegment .close ()
335
340
336
- assert expected_segment_dict == actual_segment_dict
341
+ # will record cause id instead as same exception already recorded in its subsegment
342
+ segment_two .add_exception (exception_one , stack_one , True )
343
+
344
+ segment_two .close ()
345
+
346
+ expected_segment_two_dict = {
347
+ "id" : segment_two .id ,
348
+ "name" : "test" ,
349
+ "start_time" : segment_two .start_time ,
350
+ "in_progress" : False ,
351
+ "cause" : exception_one ._cause_id ,
352
+ "trace_id" : segment_two .trace_id ,
353
+ "fault" : True ,
354
+ "end_time" : segment_two .end_time
355
+ }
356
+
357
+ actual_segment_one_dict = entity_to_dict (segment_one )
358
+ actual_segment_two_dict = entity_to_dict (segment_two )
359
+
360
+ assert expected_segment_one_dict == actual_segment_one_dict
361
+ assert expected_segment_two_dict == actual_segment_two_dict
337
362
338
363
def test_serialize_subsegment ():
339
364
0 commit comments