Skip to content

Commit 7ab91c8

Browse files
committed
fix(test): drain counter queue in follower's runner
Instead of waiting for looper to stop and return final coutner we push all updates into queue and then drain it from main loop after thread joined or times out. This makes timeout tests into soft timeout, because we are giving looper time to finish processing last batch of the changes.
1 parent db5b9bd commit 7ab91c8

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

test/unit/features/conftest.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# coding: utf-8
22

3-
# © Copyright IBM Corporation 2022, 2023.
3+
# © Copyright IBM Corporation 2022, 2024.
44
#
55
# Licensed under the Apache License, Version 2.0 (the "License");
66
# you may not use this file except in compliance with the License.
@@ -212,12 +212,13 @@ class TimeoutError(Exception):
212212

213213
def looper(changes, buf):
214214
counter = 0
215+
buf.put(counter)
215216
try:
216217
for _ in changes:
217218
counter += 1
219+
buf.put(counter)
218220
if stop_after > 0 and stop_after == counter:
219221
follower.stop()
220-
buf.put(counter)
221222
except Exception as e:
222223
buf.put(e)
223224

@@ -229,15 +230,16 @@ def main():
229230
buf = queue.Queue()
230231
thread = threading.Thread(target=looper, args=(changes, buf))
231232
thread.start()
233+
thread.join(timeout)
234+
while not buf.empty():
235+
data = buf.get()
236+
if isinstance(data, Exception):
237+
raise data
232238
while True:
233-
thread.join(timeout)
234239
if thread.is_alive():
235240
follower.stop()
236241
else:
237242
break
238-
data = buf.get()
239-
if isinstance(data, Exception):
240-
raise data
241243
return data
242244

243245
return main()

test/unit/features/test_changes_follower.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# coding: utf-8
22

3-
# © Copyright IBM Corporation 2022, 2023.
3+
# © Copyright IBM Corporation 2022, 2024.
44
#
55
# Licensed under the Apache License, Version 2.0 (the "License");
66
# you may not use this file except in compliance with the License.
@@ -458,7 +458,7 @@ def test_start(self):
458458
with some batches.
459459
"""
460460
try:
461-
self.prepare_mock_changes(batches=MAX_BATCHES)
461+
self.prepare_mock_changes(batches=3)
462462
follower = ChangesFollower(self.client, db='db')
463463
count = self.runner(follower, _Mode.LISTEN, timeout=5)
464464
except BaseException:

0 commit comments

Comments
 (0)