Skip to content

Commit fdb48af

Browse files
elprans1st1
authored andcommitted
Add proper cleanup in log listener test.
1 parent 7f533b8 commit fdb48af

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

tests/test_listeners.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -180,20 +180,24 @@ def notice_callb(con, message):
180180
" END"
181181
"$$"
182182
)
183-
con.add_log_listener(notice_callb)
184-
for cur_id in range(10):
185-
await con.execute("SELECT _test($1)", cur_id)
186183

187-
for cur_id in range(10):
188-
self.assertEqual(
189-
q1.get_nowait(),
190-
(con, cur_id, '1_%s' % cur_id))
191-
self.assertEqual(
192-
q1.get_nowait(),
193-
(con, cur_id, '2_%s' % cur_id))
184+
try:
185+
con.add_log_listener(notice_callb)
186+
for cur_id in range(10):
187+
await con.execute("SELECT _test($1)", cur_id)
194188

195-
con.remove_log_listener(notice_callb)
196-
self.assertTrue(q1.empty())
189+
for cur_id in range(10):
190+
self.assertEqual(
191+
q1.get_nowait(),
192+
(con, cur_id, '1_%s' % cur_id))
193+
self.assertEqual(
194+
q1.get_nowait(),
195+
(con, cur_id, '2_%s' % cur_id))
196+
197+
con.remove_log_listener(notice_callb)
198+
self.assertTrue(q1.empty())
199+
finally:
200+
await con.execute('DROP FUNCTION _test(i INT)')
197201

198202
@tb.with_connection_options(server_settings={
199203
'client_min_messages': 'notice'

0 commit comments

Comments
 (0)