|
| 1 | +local t = require('luatest') |
| 2 | +local replica_set = require('luatest.replica_set') |
| 3 | +local server = require('luatest.server') |
| 4 | + |
| 5 | +local g_one_member_cluster = t.group('one_member_cluster') |
| 6 | +local g_three_member_cluster = t.group('three_member_cluster') |
| 7 | + |
| 8 | +g_one_member_cluster.before_all(function(cg) |
| 9 | + cg.master = server:new{alias = 'master'} |
| 10 | + cg.master:start() |
| 11 | + -- Make `_cluster` space synchronous. |
| 12 | + cg.master:exec(function() |
| 13 | + box.ctl.promote() |
| 14 | + box.space._cluster:alter{is_sync = true} |
| 15 | + end) |
| 16 | +end) |
| 17 | + |
| 18 | +-- Test that synchronous insertion into 1-member cluster works properly. |
| 19 | +g_one_member_cluster.test_insertion = function(cg) |
| 20 | + cg.replica = server:new{alias = 'replica', box_cfg = { |
| 21 | + replication = cg.master.net_box_uri, |
| 22 | + }} |
| 23 | + cg.replica:start() |
| 24 | + cg.master:wait_for_downstream_to(cg.replica) |
| 25 | + cg.replica:exec(function() |
| 26 | + t.assert_not_equals(box.space._cluster:get{box.info.id}, nil) |
| 27 | + end) |
| 28 | +end |
| 29 | + |
| 30 | +g_one_member_cluster.after_all(function(cg) |
| 31 | + cg.master:drop() |
| 32 | + if cg.replica ~= nil then |
| 33 | + cg.replica:drop() |
| 34 | + end |
| 35 | +end) |
| 36 | + |
| 37 | +g_three_member_cluster.before_all(function(cg) |
| 38 | + cg.replica_set = replica_set:new{} |
| 39 | + cg.master = cg.replica_set:build_and_add_server{alias = 'master'} |
| 40 | + cg.master:start() |
| 41 | + cg.replica_to_be_disabled = |
| 42 | + cg.replica_set:build_and_add_server{alias = 'to_be_disabled', |
| 43 | + box_cfg = { |
| 44 | + replication = { |
| 45 | + cg.master.net_box_uri, |
| 46 | + server.build_listen_uri('replica', cg.replica_set.id), |
| 47 | + }, |
| 48 | + }} |
| 49 | + cg.replica = cg.replica_set:build_and_add_server{alias = 'replica', |
| 50 | + box_cfg = { |
| 51 | + replication = { |
| 52 | + cg.master.net_box_uri, |
| 53 | + server.build_listen_uri('to_be_disabled', cg.replica_set.id), |
| 54 | + }, |
| 55 | + }} |
| 56 | + cg.replica_set:start() |
| 57 | + |
| 58 | + -- Make `_cluster` space synchronous. |
| 59 | + cg.master:exec(function() |
| 60 | + box.ctl.promote() |
| 61 | + box.space._cluster:alter{is_sync = true} |
| 62 | + end) |
| 63 | + |
| 64 | + cg.master:wait_for_downstream_to(cg.replica_to_be_disabled) |
| 65 | + cg.master:wait_for_downstream_to(cg.replica) |
| 66 | +end) |
| 67 | + |
| 68 | +-- Test that synchronous insertion into 3-member cluster with 1 disabled node |
| 69 | +-- works properly. |
| 70 | +g_three_member_cluster.test_insertion = function(cg) |
| 71 | + cg.replica_to_be_disabled:exec(function() |
| 72 | + box.cfg{replication = ''} |
| 73 | + end) |
| 74 | + cg.replica_to_be_added = |
| 75 | + cg.replica_set:build_and_add_server{alias = 'to_be_added', |
| 76 | + box_cfg = { |
| 77 | + replication = { |
| 78 | + cg.master.net_box_uri, |
| 79 | + server.build_listen_uri('to_be_disabled', cg.replica_set.id), |
| 80 | + server.build_listen_uri('replica', cg.replica_set.id), |
| 81 | + }, |
| 82 | + }} |
| 83 | + cg.replica_to_be_added:start() |
| 84 | + cg.master:wait_for_downstream_to(cg.replica) |
| 85 | + cg.master:wait_for_downstream_to(cg.replica_to_be_added) |
| 86 | + cg.replica_to_be_added:exec(function() |
| 87 | + t.assert_not_equals(box.space._cluster:get{box.info.id}, nil) |
| 88 | + end) |
| 89 | +end |
| 90 | + |
| 91 | +g_three_member_cluster.after_all(function(cg) |
| 92 | + cg.replica_set:drop() |
| 93 | +end) |
0 commit comments