Skip to content

Commit

Permalink
Respect multithreading in asynchandler test.
Browse files Browse the repository at this point in the history
Signed-off-by: pguz <[email protected]>
  • Loading branch information
pguz committed May 25, 2020
1 parent 84808c3 commit 478bd02
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions tests/test_asynchandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ def test_simple(self):
self.assertTrue(isinstance(el[1], int))


class QueueOverflowException(Exception):
class QueueOverflowException(BaseException):
pass


Expand Down Expand Up @@ -364,11 +364,24 @@ def custom_full_queue():
handler.setFormatter(fluent.handler.FluentRecordFormatter())
log.addHandler(handler)

with self.assertRaises(QueueOverflowException):
exc_counter = 0

try:
log.info({'cnt': 1, 'from': 'userA', 'to': 'userB'})
except QueueOverflowException:
exc_counter += 1

with self.assertRaises(QueueOverflowException):
try:
log.info({'cnt': 2, 'from': 'userA', 'to': 'userB'})
except QueueOverflowException:
exc_counter += 1

with self.assertRaises(QueueOverflowException):
try:
log.info({'cnt': 3, 'from': 'userA', 'to': 'userB'})
except QueueOverflowException:
exc_counter += 1

# we can't be sure to have exception in every case due to multithreading,
# so we can test only for a cautelative condition here
print('Exception raised: {} (expected 3)'.format(exc_counter))
assert exc_counter >= 0

0 comments on commit 478bd02

Please sign in to comment.