Skip to content
Snippets Groups Projects
Commit 3c924094 authored by Georgy Moshkin's avatar Georgy Moshkin :speech_balloon:
Browse files

test: reduce test_log_rollback flakiness

parent 15ddcce4
No related branches found
No related tags found
1 merge request!1311test: cleanup cluster.cas vs instance.cas inconsistencies
Pipeline #51518 failed
This commit is part of merge request !1311. Comments created here will be created in the context of that merge request.
......@@ -58,6 +58,8 @@ PICO_SERVICE_ID = 32
class ErrorCode:
Loading = 116
Other = 10000
NotALeader = 10001
StorageCorrupted = 10002
TermMismatch = 10003
RaftLogUnavailable = 10004
RaftLogCompacted = 10005
......@@ -71,6 +73,23 @@ class ErrorCode:
LeaderUnknown = 10018
PluginError = 10019
# Make sure this matches this list in picoplugin::error_code::ErrorCode::is_retriable_for_cas
retriable_for_cas = set(
[
LeaderUnknown,
NotALeader,
TermMismatch,
RaftLogCompacted,
RaftLogUnavailable,
CasEntryTermMismatch,
CasConflictFound,
]
)
@classmethod
def is_retriable_for_cas(cls, code):
return code in cls.retriable_for_cas
def eprint(*args, **kwargs):
print(*args, file=sys.stderr, **kwargs)
......
import pytest
import time
from conftest import Cluster, Instance, TarantoolError, Retriable
from conftest import Cluster, Instance, TarantoolError, Retriable, ErrorCode
@pytest.fixture
......@@ -65,12 +65,32 @@ def test_log_rollback(cluster3: Cluster):
key = 0
def propose_state_change(srv: Instance, value):
def propose_state_change(srv: Instance, value, timeout=10):
deadline = time.time() + timeout
nonlocal key
index = cluster3.cas(
"insert", "_pico_property", (f"check{key}", value), instance=srv
)
srv.raft_wait_index(index)
while True:
try:
index = cluster3.cas(
"insert",
"_pico_property",
(f"check{key}", value),
instance=srv,
)
srv.raft_wait_index(index)
break
except TarantoolError as e:
print(f"\x1b[33m### CaS error: {e}", end="")
if time.time() > deadline:
print(", timeout\x1b[0m")
raise
if ErrorCode.is_retriable_for_cas(e.args[0]):
print(", retrying...\x1b[0m")
time.sleep(0.1)
continue
print(", failure!\x1b[0m")
raise
key += 1
propose_state_change(i1, "i1 is a leader")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment