Skip to content

Commit c98aaa3

Browse files
committed
clean up handling and testing of SEQUENCE errors
1 parent b619ec8 commit c98aaa3

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

convex_api/convex_api.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ def send(self, transaction, account, language=None, sequence_retry_count=20):
5656
raise TypeError('The transaction must be a type str')
5757

5858
result = None
59+
max_sleep_time_seconds = 1
5960
while sequence_retry_count >= 0:
6061
try:
6162
hash_data = self._transaction_prepare(account.address, transaction, language=language)
@@ -66,7 +67,9 @@ def send(self, transaction, account, language=None, sequence_retry_count=20):
6667
if sequence_retry_count == 0:
6768
raise
6869
sequence_retry_count -= 1
69-
time.sleep((secrets.randbelow(1000) + 1) / 1000)
70+
# now sleep < 1 second for some random milli secconds
71+
sleep_time = (secrets.randbelow(max_sleep_time_seconds * 1000) + 1) / 1000
72+
time.sleep(sleep_time)
7073
else:
7174
raise
7275
else:

tests/intergration/test_convex_multi_thread.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ def process_on_convex(convex, test_account):
1616
values = []
1717
inc_values = []
1818
is_sent = False
19-
for counter in range(0, 4):
19+
for counter in range(0, secrets.randbelow(4) + 1):
2020
for index in range(secrets.randbelow(10) + 1):
2121
value = secrets.randbelow(1000)
2222
values.append(str(value))
2323
inc_values.append(value + 1)
2424
value_text = " ".join(values)
25-
result = convex.send(f'(map inc [{value_text}])', test_account)
25+
result = convex.send(f'(map inc [{value_text}])', test_account, sequence_retry_count=100)
2626
assert(result)
2727
assert('id' in result)
2828
assert('value' in result)
@@ -31,7 +31,7 @@ def process_on_convex(convex, test_account):
3131

3232
def test_convex_api_multi_thread(convex_url, test_account):
3333

34-
process_count = 4
34+
process_count = 8
3535
convex = ConvexAPI(convex_url)
3636
auto_topup_account(convex, test_account)
3737
process_list = []

0 commit comments

Comments
 (0)