Tarantool development patches archive
 help / color / mirror / Atom feed
From: Serge Petrenko <sergepetrenko@tarantool.org>
To: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>,
	tarantool-patches@dev.tarantool.org
Subject: Re: [Tarantool-patches] [PATCH 4/8] test: introduce raft unit tests
Date: Mon, 21 Dec 2020 10:36:19 +0300	[thread overview]
Message-ID: <7469b83f-dde4-e0b6-3509-8fc009a8e906@tarantool.org> (raw)
In-Reply-To: <36a79bd1-6349-cc6c-a90c-78b473a8f5f2@tarantool.org>


20.12.2020 20:28, Vladislav Shpilevoy пишет:
> Thanks for the review!
>
>>>>> diff --git a/test/unit/raft.c b/test/unit/raft.c
>>>>> new file mode 100644
>>>>> index 000000000..dfb5f8e43
>>>>> --- /dev/null
>>>>> +++ b/test/unit/raft.c
>>>>> +
>>>>> +static void
>>>>> +raft_test_vote_skip(void)
>>>>> +{
>>>>> +    raft_start_test(33);
>>>>> +    struct raft_node node;
>>>>> +    raft_node_create(&node);
>>>>> +
>>>>> +    /* Everything is skipped if the term is outdated. */
>>>> 1. Let's also test a case when vote response has greater term than the candidate itself.
>>> Good idea. Below is the diff (without .result file diff, to be
>>> short).
>>>
>>> ====================
>>> @@ -346,7 +346,7 @@ raft_test_vote(void)
>>>    static void
>>>    raft_test_vote_skip(void)
>>>    {
>>> -    raft_start_test(33);
>>> +    raft_start_test(37);
>>>        struct raft_node node;
>>>        raft_node_create(&node);
>>>    @@ -507,6 +507,35 @@ raft_test_vote_skip(void)
>>>          raft_node_cfg_is_candidate(&node, true);
>>>    +    /*
>>> +     * Vote response with a bigger term must be skipped, but it will bump
>>> +     * the term.
>>> +     */
>>> +
>>> +    /* Re-create the node so as not to write the vclock each time. */
>>> +    raft_node_destroy(&node);
>>> +    raft_node_create(&node);
>>> +
>>> +    raft_run_next_event();
>>> +    is(node.raft.state, RAFT_STATE_CANDIDATE, "became candidate");
>>> +    is(node.raft.term, 2, "term is bumped");
>>> +
>>> +    is(raft_node_send_vote_response(&node,
>>> +        3 /* Term. */,
>>> +        1 /* Vote. */,
>>> +        2 /* Source. */
>>> +    ), 0, "message is accepted");
>>> +
>>> +    ok(raft_node_check_full_state(&node,
>>> +        RAFT_STATE_CANDIDATE /* State. */,
>>> +        0 /* Leader. */,
>>> +        3 /* Term. */,
>>> +        1 /* Vote. */,
>>> +        3 /* Volatile term. */,
>>> +        1 /* Volatile vote. */,
>>> +        "{0: 3}" /* Vclock. */
>>> +    ), "term is bumped and became candidate");
>>> +
>>>        raft_node_destroy(&node);
>>>        raft_finish_test();
>>>    }
>>> ====================
>>
>> I'd also set the quorum to 2 to make sure the node doesn't become leader in the old term
>>
>> and that it doesn't count votes from a bigger term, but maybe that's an overkill for this test.
>>
>> So, up to you.
> Sounds good, added:
>
> ====================
> @@ -525,6 +525,11 @@ raft_test_vote_skip(void)
>   	/* Re-create the node so as not to write the vclock each time. */
>   	raft_node_destroy(&node);
>   	raft_node_create(&node);
> +	/*
> +	 * Set quorum to 2 to ensure the node does not count the bigger-term
> +	 * vote and doesn't become a leader.
> +	 */
> +	raft_node_cfg_election_quorum(&node, 2);
>   
>   	raft_run_next_event();

Thanks!

LGTM.

-- 
Serge Petrenko

  reply	other threads:[~2020-12-21  7:36 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-13 17:15 [Tarantool-patches] [PATCH 0/8] Raft module, part 4 - " Vladislav Shpilevoy
2020-12-13 17:15 ` [Tarantool-patches] [PATCH 1/8] fakesys: fix ev_is_active not working on fake timers Vladislav Shpilevoy
2020-12-15  9:42   ` Serge Petrenko
2020-12-13 17:15 ` [Tarantool-patches] [PATCH 2/8] fakesys: introduce fakeev_timer_remaining() Vladislav Shpilevoy
2020-12-15  9:43   ` Serge Petrenko
2020-12-13 17:15 ` [Tarantool-patches] [PATCH 3/8] raft: introduce raft_ev Vladislav Shpilevoy
2020-12-15 10:02   ` Serge Petrenko
2020-12-13 17:15 ` [Tarantool-patches] [PATCH 4/8] test: introduce raft unit tests Vladislav Shpilevoy
2020-12-13 18:10   ` Vladislav Shpilevoy
2020-12-16 13:03   ` Serge Petrenko
2020-12-17 22:44     ` Vladislav Shpilevoy
2020-12-18  8:17       ` Serge Petrenko
2020-12-20 17:28         ` Vladislav Shpilevoy
2020-12-21  7:36           ` Serge Petrenko [this message]
2020-12-13 17:15 ` [Tarantool-patches] [PATCH 5/8] raft: fix crash when received 0 term message Vladislav Shpilevoy
2020-12-16 13:05   ` Serge Petrenko
2020-12-13 17:15 ` [Tarantool-patches] [PATCH 6/8] raft: fix ignorance of bad state receipt Vladislav Shpilevoy
2020-12-16 13:06   ` Serge Petrenko
2020-12-13 17:15 ` [Tarantool-patches] [PATCH 7/8] raft: fix crash on election timeout decrease Vladislav Shpilevoy
2020-12-16 13:08   ` Serge Petrenko
2020-12-13 17:15 ` [Tarantool-patches] [PATCH 8/8] raft: fix crash on death " Vladislav Shpilevoy
2020-12-16 13:10   ` Serge Petrenko
2020-12-21 16:50 ` [Tarantool-patches] [PATCH 0/8] Raft module, part 4 - unit tests Vladislav Shpilevoy
2020-12-21 17:29 ` Vladislav Shpilevoy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7469b83f-dde4-e0b6-3509-8fc009a8e906@tarantool.org \
    --to=sergepetrenko@tarantool.org \
    --cc=tarantool-patches@dev.tarantool.org \
    --cc=v.shpilevoy@tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH 4/8] test: introduce raft unit tests' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox