Skip to content
Snippets Groups Projects
Verified Commit 7b94717a authored by Yaroslav Dynnikov's avatar Yaroslav Dynnikov
Browse files

fix: pytest wait_ready implementation

Waiting for a valid `leader_id` on a node isn't enough. It may already
have one, but still be a Learner. Instead, the fixture should wait until
the node is promoted to voter.
parent bf02c082
No related branches found
No related tags found
1 merge request!89fix: pytest wait_ready implementation
Pipeline #4526 passed
...@@ -589,6 +589,8 @@ fn postjoin(args: &args::Run) { ...@@ -589,6 +589,8 @@ fn postjoin(args: &args::Run) {
} }
}; };
} }
node.mark_as_ready();
} }
fn main_tarantool(args: args::Tarantool) -> ! { fn main_tarantool(args: args::Tarantool) -> ! {
......
...@@ -53,6 +53,7 @@ pub struct Status { ...@@ -53,6 +53,7 @@ pub struct Status {
pub id: u64, pub id: u64,
pub leader_id: u64, pub leader_id: u64,
pub raft_state: String, pub raft_state: String,
pub is_ready: bool,
} }
/// The heart of `traft` module - the Node. /// The heart of `traft` module - the Node.
...@@ -103,6 +104,7 @@ impl Node { ...@@ -103,6 +104,7 @@ impl Node {
id: cfg.id, id: cfg.id,
leader_id: 0, leader_id: 0,
raft_state: "Follower".into(), raft_state: "Follower".into(),
is_ready: false,
})); }));
let main_loop_fn = { let main_loop_fn = {
...@@ -136,6 +138,11 @@ impl Node { ...@@ -136,6 +138,11 @@ impl Node {
self.status.borrow().clone() self.status.borrow().clone()
} }
pub fn mark_as_ready(&self) {
self.status.borrow_mut().is_ready = true;
self.status_cond.broadcast();
}
pub fn wait_status(&self) { pub fn wait_status(&self) {
self.status_cond.wait(); self.status_cond.wait();
} }
......
...@@ -118,6 +118,7 @@ class RaftStatus: ...@@ -118,6 +118,7 @@ class RaftStatus:
id: int id: int
raft_state: str raft_state: str
leader_id: int leader_id: int
is_ready: bool
def __eq__(self, other): def __eq__(self, other):
match other: match other:
...@@ -139,9 +140,6 @@ class RaftStatus: ...@@ -139,9 +140,6 @@ class RaftStatus:
return False return False
def is_ready(self):
return self.leader_id > INVALID_ID
@dataclass @dataclass
class Instance: class Instance:
...@@ -280,7 +278,7 @@ class Instance: ...@@ -280,7 +278,7 @@ class Instance:
@funcy.retry(tries=20, timeout=0.1) @funcy.retry(tries=20, timeout=0.1)
def wait_ready(self): def wait_ready(self):
status = self.__raft_status() status = self.__raft_status()
assert status.is_ready() assert status.is_ready
self.raft_id = status.id self.raft_id = status.id
@funcy.retry(tries=4, timeout=0.1, errors=AssertionError) @funcy.retry(tries=4, timeout=0.1, errors=AssertionError)
......
...@@ -36,6 +36,7 @@ def test_raft_status(): ...@@ -36,6 +36,7 @@ def test_raft_status():
id=1, id=1,
raft_state="SomeState", raft_state="SomeState",
leader_id=1, leader_id=1,
is_ready=False,
) )
assert (s == "SomeState") is True assert (s == "SomeState") is True
...@@ -48,13 +49,10 @@ def test_raft_status(): ...@@ -48,13 +49,10 @@ def test_raft_status():
assert (s == ("OtherState", 1)) is False assert (s == ("OtherState", 1)) is False
assert (s == s) is True assert (s == s) is True
assert (s == RaftStatus(s.id, s.raft_state, s.leader_id)) is True assert (s == RaftStatus(s.id, s.raft_state, s.leader_id, True)) is True
assert (s == RaftStatus(-1, s.raft_state, s.leader_id)) is False assert (s == RaftStatus(-1, s.raft_state, s.leader_id, True)) is False
assert (s == RaftStatus(s.id, "OtherState", s.leader_id)) is False assert (s == RaftStatus(s.id, "OtherState", s.leader_id, True)) is False
assert (s == RaftStatus(s.id, s.raft_state, -1)) is False assert (s == RaftStatus(s.id, s.raft_state, -1, True)) is False
assert RaftStatus(1, "Follower", 0).is_ready() is False
assert RaftStatus(1, "Follower", 1).is_ready() is True
def test_call_normalization(instance: Instance): def test_call_normalization(instance: Instance):
......
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