60def test_refcounting():
61 record = namedtuple("coracool_record", "since until channel elements")
62 element = namedtuple("element", "group id")
63
64 from time import time
65 start = time()
66
67
68
69
70 repr([1])
71
72 objects = None
73
74 before_objects =
set(id(x)
for x
in gc.get_objects())
75 gc.collect()
76
77 try: raise RuntimeError
78 except Exception: pass
79
80 print(
"Objects alive before call:", len(gc.get_objects()))
81
82 try:
84 cool.ChannelSelection(), "", ["group", "id"],
85 record, element)
86
87 except Exception as e:
88 print(
"Caught exception ", e)
89 del e
90
91 elapsed = time() - start
92 print(
"Took %.3f to browse folder" % elapsed)
93
94 assert objects is not None, 'Null return from browse_coracool'
95
97 print(
"Result length =", len(objects))
98 print(
"Result index 0 length =", len(objects[0]))
99 print(
"Result index 0 =", objects[0])
100 del objects
101
102
103 print(
"Objects alive before cleanup:", len(gc.get_objects()))
104
105 gc.collect()
106
107 print(
"Objects alive after:", len(gc.get_objects()))
108
109 after_objects = gc.get_objects()
110
111 new_objects =
set(id(x)
for x
in after_objects) - before_objects
112
113
114 new_objects = [x for x in after_objects if id(x) in new_objects and x != before_objects and x != new_objects]
115
116 assert new_objects == [], 'Lingering objects after garbage collection'
117
118