Example #1
0
def test_kickoff(clusters):
    assert clusters != []
    kick_off("test1")
    kick_off("test2")
    kick_off("test3")
    kick_off("test4")
    kick_off("test5")
Example #2
0
def clusters():
    for id in raft.default_clusters:
        spawn_client_thread(id)
    time.sleep(1)
    yield raft.default_clusters
    for (id, _) in raft.clusters.items():
        kick_off(id)
    time.sleep(0.1)
Example #3
0
def test_sync_log_after_follower_kickoff(clusters):
    leaders = find_leaders(clusters)
    assert leaders != []
    leader = leaders[0]
    append_logs(leader, ["test1", "test2", "test3"])
    time.sleep(3)
    followers = find_followers(clusters)
    kicked_off_follower = followers[0]
    kick_off(kicked_off_follower)
    spawn_client_thread(kicked_off_follower)
    time.sleep(3)
    logs = request_all_logs(clusters)
    assert logs[leader].logs == ["test1", "test2", "test3"]
    for k in clusters:
        assert logs[k].logs == ["test1", "test2", "test3"]
Example #4
0
def test_new_leader_after_kick_off(clusters):
    leaders = find_leaders(clusters)
    assert len(leaders) == 1
    leader = leaders[0]
    kick_off(leader)
    time.sleep(3)
    logs = request_all_logs(clusters)

    leader_cnt = count_role(logs, "leader")
    candidate_cnt = count_role(logs, "candidate")
    follower_cnt = count_role(logs, "follower")

    assert candidate_cnt == 0
    assert follower_cnt == 3
    assert leader_cnt == 1
Example #5
0
def test_sync_log_after_leader_kickoff(clusters):
    leaders = find_leaders(clusters)
    assert len(leaders) == 1
    leader = leaders[0]
    append_logs(leader, ["test1", "test2", "test3"])
    time.sleep(3)
    logs = request_all_logs(clusters)
    for k in clusters:
        assert logs[k].logs == ["test1", "test2", "test3"]
    kick_off(leader)
    spawn_client_thread(leader)
    time.sleep(3)
    leaders = find_leaders(clusters)
    assert len(leaders) == 1
    leader = leaders[0]
    logs = request_all_logs(clusters)
    assert logs[leader].logs == ["test1", "test2", "test3"]
    for k in clusters:
        assert logs[k].logs == ["test1", "test2", "test3"]
Example #6
0
def test_no_leader_after_kick_off(clusters):
    leaders = find_leaders(clusters)
    followers = find_followers(clusters)
    kick_off(leaders[0])
    kick_off(followers[0])
    kick_off(followers[1])
    time.sleep(3)
    logs = request_all_logs(clusters)

    leader_cnt = count_role(logs, "leader")

    assert leader_cnt == 0
Example #7
0
def test_extra_nodes(clusters):
    spawn_client_thread("test6")
    time.sleep(1)
    kick_off("test6")
Example #8
0
def test_restart(clusters):
    kick_off("test3")
    spawn_client_thread("test3")