Skip to content

Commit d5c86ec

Browse files
committed
delivery.report.only.error test: verify GC of callback reference
1 parent 9eaefa5 commit d5c86ec

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

examples/integration_test.py

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import uuid
2626
import sys
2727
import json
28+
import gc
2829
from copy import copy
2930

3031
try:
@@ -141,6 +142,9 @@ def verify_producer():
141142

142143

143144

145+
# Global variable to track garbage collection of suppressed on_delivery callbacks
146+
DrOnlyTestSuccess_gced = 0
147+
144148
def test_producer_dr_only_error():
145149
"""
146150
The C delivery.report.only.error configuration property
@@ -157,7 +161,7 @@ def test_producer_dr_only_error():
157161
'broker.address.family':'v4',
158162
"delivery.report.only.error":True})
159163

160-
class DrOnlyTest (object):
164+
class DrOnlyTestErr (object):
161165
def __init__ (self):
162166
self.remaining = 1
163167

@@ -167,28 +171,45 @@ def handle_err (self, err, msg):
167171
assert err is not None
168172
self.remaining -= 1
169173

174+
class DrOnlyTestSuccess (object):
170175
def handle_success (self, err, msg):
171176
""" This delivery handler should never get called """
172177
# FIXME: Can we verify that it is actually garbage collected?
173178
assert "GOOD:" in msg.value().decode('utf-8')
174179
assert err is None
175180
assert False, "should never come here"
176181

177-
state = DrOnlyTest()
182+
def __del__ (self):
183+
# Indicate that gc has hit this object.
184+
global DrOnlyTestSuccess_gced
185+
DrOnlyTestSuccess_gced = 1
178186

179187
print('only.error: Verifying delivery.report.only.error')
188+
189+
state = DrOnlyTestErr()
180190
p.produce(topic, "BAD: This message will make not make it".encode('utf-8'),
181191
partition=99, on_delivery=state.handle_err)
182192

193+
not_called_state = DrOnlyTestSuccess()
183194
p.produce(topic, "GOOD: This message will make make it".encode('utf-8'),
184-
on_delivery=state.handle_success)
195+
on_delivery=not_called_state.handle_success)
196+
197+
# Garbage collection should not kick in yet for not_called_state
198+
# since there is a on_delivery reference to it.
199+
not_called_state = None
200+
gc.collect()
201+
global DrOnlyTestSuccess_gced
202+
assert DrOnlyTestSuccess_gced == 0
185203

186-
print('only.error: Waiting for flush')
204+
print('only.error: Waiting for flush of %d messages' % len(p))
187205
p.flush(10000)
188206

189207
print('only.error: Remaining messages now %d' % state.remaining)
190208
assert state.remaining == 0
191209

210+
# Now with all messages flushed the reference to not_called_state should be gone.
211+
gc.collect()
212+
assert DrOnlyTestSuccess_gced == 1
192213

193214

194215
def verify_avro():

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy