mirror of
https://github.com/simon987/hexlib.git
synced 2025-12-14 07:09:05 +00:00
Fix @retry
This commit is contained in:
27
test/test_retry.py
Normal file
27
test/test_retry.py
Normal file
@@ -0,0 +1,27 @@
|
||||
from unittest import TestCase
|
||||
from hexlib.db import VolatileState, VolatileBooleanState
|
||||
from hexlib.misc import retry
|
||||
|
||||
|
||||
class TestRetry(TestCase):
|
||||
|
||||
def test_simple(self):
|
||||
@retry(attempts=3)
|
||||
def a(i):
|
||||
return i + 1
|
||||
|
||||
self.assertEqual(a(1), 2)
|
||||
|
||||
def test_error(self):
|
||||
arr = []
|
||||
|
||||
def cb(e):
|
||||
arr.append(e)
|
||||
|
||||
@retry(attempts=3, callback=cb)
|
||||
def a(i):
|
||||
raise Exception("err")
|
||||
|
||||
a(1)
|
||||
|
||||
self.assertEqual(3, len(arr))
|
||||
Reference in New Issue
Block a user