Skip to content

box.ctl.promote() code in some simple places is not tested at all #6033

@Gerold103

Description

@Gerold103

I applied this diff:

diff --git a/src/box/box.cc b/src/box/box.cc
index 59925962d..b026dfe05 100644
--- a/src/box/box.cc
+++ b/src/box/box.cc
@@ -1582,16 +1582,21 @@ box_promote(void)
 		 */
 		if (box_election_mode == ELECTION_MODE_MANUAL)
 			raft_stop_candidate(box_raft(), false);
+		else
+			assert(false);
 		if (rc != 0) {
+			assert(false);
 			in_promote = false;
 			return -1;
 		}
 		if (!box_raft()->is_enabled) {
+			assert(false);
 			diag_set(ClientError, ER_RAFT_DISABLED);
 			in_promote = false;
 			return -1;
 		}
 		if (box_raft()->state != RAFT_STATE_LEADER) {
+			assert(false);
 			diag_set(ClientError, ER_INTERFERING_PROMOTE,
 				 box_raft()->leader);
 			in_promote = false;

And all the tests passed. It is not something hard to reproduce. For example:

box.cfg{
    replication_synchro_timeout = 1,
    election_mode = 'manual',
}
box.error.injection.set('ERRINJ_WAL_DELAY', true)
f = require('fiber').create(function() box.ctl.promote() end)
box.cfg{election_mode = 'voter'}
box.error.injection.set('ERRINJ_WAL_DELAY', false)
f:cancel()

Helps to test election mode change during elections:

Process 70218 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = hit program assert
    frame #4: 0x0000000100123d13 tarantool`::box_promote() at box.cc:1586:4
   1583			if (box_election_mode == ELECTION_MODE_MANUAL)
   1584				raft_stop_candidate(box_raft(), false);
   1585			else
-> 1586				assert(false);
   1587			if (rc != 0) {
   1588				assert(false);
   1589				in_promote = false;
Target 0: (tarantool) stopped.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions