raft: fix crash on candidate cfg during WAL write

Raft state machine crashed if it was configured to be a candidate
during a WAL write with a known leader.

It tried to start waiting for the leader death, but should have
waited for the WAL write end first.

The code tried to handle it, but the order of 'if' conditions was
wrong. WAL write being in progress was checked last, but should
have been checked first.

Closes #5506
46 jobs for gerold103/gh-5506-raft-crash in 37 minutes and 29 seconds (queued for 3 minutes and 16 seconds)
latest
Status Name Job ID Coverage
  Static Analysis
passed luacheck #839509490
deploy_test

00:00:53

 
  Test
passed centos_6 #839509535
deploy

00:06:07

passed centos_7 #839509537
deploy_test

00:07:40

passed centos_8 #839509539
deploy_test

00:05:00

passed debian_10 #839509580
deploy

00:05:20

passed debian_8 #839509573
deploy

00:06:36

passed debian_9 #839509577
deploy

00:04:48

failed debug #841895085
docker_test

00:09:42

passed default_gcc_centos_7 #839509532
deploy_test

00:06:41

passed fedora_28 #839509541
deploy_test

00:05:56

passed fedora_29 #839509543
deploy_test

00:03:45

passed fedora_30 #839509545
deploy_test

00:05:35

passed fedora_31 #839509548
deploy_test

00:10:25

passed freebsd_12_release #841895094
vms_freebsd_12

00:14:05

passed opensuse_15_1 #839509582
deploy_test

00:04:09

passed opensuse_15_2 #839509583
deploy_test

00:04:08

passed osx_13_release #841895090
osx_13

00:08:52

passed osx_14_release #839509524
osx_14

00:07:40

passed osx_15_release #841895092
osx_15

00:05:20

passed osx_15_release_lto #841895093
osx_15

00:06:35

failed out_of_source #841895082
deploy_test

00:11:40

passed release #839509492
docker_test

00:04:50

passed release_asan_clang11 #839509520
docker_test

00:10:54

passed release_clang #839509494
docker_test

00:10:06

passed release_lto #839509516
docker_test

00:10:47

passed release_lto_clang11 #839509518
docker_test

00:06:56

passed sources #839509533
deploy

00:00:20

passed static_build #839509586
docker_test

00:04:01

passed static_build_cmake_linux #839509589
docker_test

00:06:23

passed static_build_cmake_osx_15 #841895095
osx_15

00:06:43

passed ubuntu_14_04 #839509550
deploy

00:08:07

passed ubuntu_16_04 #839509554
deploy

00:07:16

passed ubuntu_18_04 #839509558
deploy

00:06:54

passed ubuntu_19_10 #839509563
deploy

00:06:48

passed ubuntu_20_04 #839509567
deploy

00:05:04

failed debug #839509493
docker_test

00:08:14

failed freebsd_12_release #839509530
vms_freebsd_12

00:15:53

failed osx_13_release #839509522
osx_13

00:08:47

failed osx_15_release #839509526
osx_15

00:00:31

failed osx_15_release_lto #839509528
osx_15

00:00:31

failed out_of_source #839509491
deploy_test

00:13:38

failed static_build_cmake_osx_15 #839509593
osx_15

00:00:31

 
  Long Tests
skipped jepsen-cluster #839509605
mcs_jepsen_docker allowed to fail manual
skipped jepsen-cluster-txm #839509609
mcs_jepsen_docker allowed to fail manual
skipped jepsen-single-instance #839509598
mcs_jepsen_docker allowed to fail manual
skipped jepsen-single-instance-txm #839509601
mcs_jepsen_docker allowed to fail manual
 
Name Stage Failure
failed
out_of_source Test
- [engine/null.test.lua, memtx]
- [engine/errinj_ddl.test.lua, vinyl]
...
.travis.mk:221: recipe for target 'test_oos_no_deps' failed
make: *** [test_oos_no_deps] Error 3
make[1]: *** [test_oos_build] Error 2
make[1]: Leaving directory `/home/gitlab-runner/builds/PLzQjNYv/0/tarantool/tarantool'
make: *** [test_oos_build] Error 2
ERROR: Job failed: exit status 1
failed
debug Test
make[1]: *** [test_coverage_debian_no_deps] Error 3
.gitlab.mk:6: recipe for target 'test_coverage_debian_no_deps' failed
make: *** [test_coverage_debian_no_deps] Error 2
Running after script...
$ cp -r test/var/artifacts .
Uploading artifacts...
artifacts: found 22 matching files
Uploading artifacts to coordinator... ok
id=841895085 responseStatus=201 Created token=_Ckizqkx
ERROR: Job failed: exit code 1