def test_structure_intact():

    segment = FacadeSegment('name', 'id', 'id', True)
    subsegment = Subsegment('name', 'local', segment)
    subsegment2 = Subsegment('name', 'local', segment)
    segment.add_subsegment(subsegment)
    subsegment.add_subsegment(subsegment2)

    assert segment.subsegments[0] is subsegment
    assert subsegment.subsegments[0] is subsegment2
예제 #2
0
def test_reference_counting():

    segment = Segment('seg')
    subsegment = Subsegment('sub', 'local', segment)
    segment.add_subsegment(subsegment)
    subsegment = Subsegment('sub', 'local', segment)
    subsubsegment = Subsegment('subsub', 'local', segment)
    subsegment.add_subsegment(subsubsegment)

    assert not segment.ready_to_send()
    assert segment.ref_counter.get_current() == 2

    subsubsegment.close()
    assert not segment.ready_to_send()
    assert segment.ref_counter.get_current() == 1

    subsegment.close()
    assert not segment.ready_to_send()
    assert segment.ref_counter.get_current() == 0

    segment.close()
    assert segment.ready_to_send()
    assert segment.get_total_subsegments_size() == 2