diff --git a/test/replication/join_vclock.result b/test/replication/join_vclock.result index a9781073d44af8a79d3457047a3262a1dbb78e1a..82288907c744f5b0ef4a499d43e8f3e16434272c 100644 --- a/test/replication/join_vclock.result +++ b/test/replication/join_vclock.result @@ -1,17 +1,17 @@ -fiber = require('fiber') ---- -... -env = require('test_run') +test_run = require('test_run').new() --- ... -replica_set = require('fast_replica') +test_run:cmd("create server master with script='replication/master1.lua'") --- +- true ... -test_run = env.new() +test_run:cmd('start server master') --- +- true ... -engine = test_run:get_cfg('engine') +test_run:cmd("switch master") --- +- true ... errinj = box.error.injection --- @@ -20,6 +20,9 @@ errinj.set("ERRINJ_RELAY_FINAL_SLEEP", true) --- - ok ... +engine = test_run:get_cfg('engine') +--- +... box.schema.user.grant('guest', 'replication') --- ... @@ -29,61 +32,79 @@ s = box.schema.space.create('test', {engine = engine}); index = s:create_index('primary') --- ... +fiber = require('fiber') +--- +... ch = fiber.channel(1) --- ... done = false --- ... -function repl_f() local i = 0 while not done do s:replace({i, i}) fiber.sleep(0.001) i = i + 1 end ch:put(true) end +function repl_f() local i = 0 while not done do s:replace({i, i}) fiber.sleep(0.001) i = i + 1 end ch:put(i) end --- ... _ = fiber.create(repl_f) --- ... -replica_set.join(test_run, 1) +test_run:cmd("create server replica with rpl_master=master, script='replication/replica.lua'") +--- +- true +... +test_run:cmd("start server replica") --- +- true ... -test_run:cmd("switch replica1") +test_run:cmd("switch replica") --- - true ... -test_run:cmd("switch default") +test_run:cmd("switch master") --- - true ... done = true --- ... -ch:get() +count = ch:get() --- -- true ... errinj.set("ERRINJ_RELAY_FINAL_SLEEP", false) --- - ok ... -test_run:cmd("switch replica1") +test_run:cmd("switch replica") --- - true ... -cnt = box.space.test.index[0]:count() +test_run:cmd("setopt delimiter ';'") --- +- true ... -box.space.test.index.primary:max()[1] == cnt - 1 +-- Wait for all tuples to be inserted on replica +test_run:wait_cond(function() + return box.space.test.index.primary:max()[1] == test_run:eval('master', 'count')[1] - 1 +end); --- - true ... -test_run:cmd("switch default") +test_run:cmd("setopt delimiter ''"); --- - true ... -replica_set.drop_all(test_run) +replica_count = box.space.test.index.primary:count() master_count = test_run:eval('master', 'count')[1] --- ... -box.space.test:drop() +-- Verify that there are the same amount of tuples on master and replica +replica_count == master_count or {replica_count, master_count} --- +- true +... +-- Cleanup. +test_run:cmd('switch default') +--- +- true ... -box.schema.user.revoke('guest', 'replication') +test_run:drop_cluster({'master', 'replica'}) --- ... diff --git a/test/replication/join_vclock.test.lua b/test/replication/join_vclock.test.lua index 0b60dffc2c03535b03c54429018b5951be19369a..7e21a7d09244abb21efd0f816ff0f528e9a2e7f3 100644 --- a/test/replication/join_vclock.test.lua +++ b/test/replication/join_vclock.test.lua @@ -1,35 +1,44 @@ -fiber = require('fiber') -env = require('test_run') -replica_set = require('fast_replica') -test_run = env.new() -engine = test_run:get_cfg('engine') +test_run = require('test_run').new() + +test_run:cmd("create server master with script='replication/master1.lua'") +test_run:cmd('start server master') +test_run:cmd("switch master") errinj = box.error.injection errinj.set("ERRINJ_RELAY_FINAL_SLEEP", true) +engine = test_run:get_cfg('engine') box.schema.user.grant('guest', 'replication') s = box.schema.space.create('test', {engine = engine}); index = s:create_index('primary') +fiber = require('fiber') ch = fiber.channel(1) done = false -function repl_f() local i = 0 while not done do s:replace({i, i}) fiber.sleep(0.001) i = i + 1 end ch:put(true) end +function repl_f() local i = 0 while not done do s:replace({i, i}) fiber.sleep(0.001) i = i + 1 end ch:put(i) end _ = fiber.create(repl_f) -replica_set.join(test_run, 1) -test_run:cmd("switch replica1") +test_run:cmd("create server replica with rpl_master=master, script='replication/replica.lua'") +test_run:cmd("start server replica") +test_run:cmd("switch replica") -test_run:cmd("switch default") +test_run:cmd("switch master") done = true -ch:get() +count = ch:get() errinj.set("ERRINJ_RELAY_FINAL_SLEEP", false) -test_run:cmd("switch replica1") -cnt = box.space.test.index[0]:count() -box.space.test.index.primary:max()[1] == cnt - 1 -test_run:cmd("switch default") - -replica_set.drop_all(test_run) -box.space.test:drop() -box.schema.user.revoke('guest', 'replication') +test_run:cmd("switch replica") +test_run:cmd("setopt delimiter ';'") +-- Wait for all tuples to be inserted on replica +test_run:wait_cond(function() + return box.space.test.index.primary:max()[1] == test_run:eval('master', 'count')[1] - 1 +end); +test_run:cmd("setopt delimiter ''"); +replica_count = box.space.test.index.primary:count() master_count = test_run:eval('master', 'count')[1] +-- Verify that there are the same amount of tuples on master and replica +replica_count == master_count or {replica_count, master_count} + +-- Cleanup. +test_run:cmd('switch default') +test_run:drop_cluster({'master', 'replica'}) diff --git a/test/replication/replica_apply_order.result b/test/replication/replica_apply_order.result new file mode 100644 index 0000000000000000000000000000000000000000..513b722a79670b876e65bed7a2f5fe71f8f21502 --- /dev/null +++ b/test/replication/replica_apply_order.result @@ -0,0 +1,121 @@ +-- test-run result file version 2 +fiber = require('fiber') + | --- + | ... +env = require('test_run') + | --- + | ... +replica_set = require('fast_replica') + | --- + | ... +test_run = env.new() + | --- + | ... +engine = test_run:get_cfg('engine') + | --- + | ... + +errinj = box.error.injection + | --- + | ... +errinj.set("ERRINJ_RELAY_FINAL_SLEEP", true) + | --- + | - ok + | ... + +box.schema.user.grant('guest', 'replication') + | --- + | ... +s = box.schema.space.create('test', {engine = engine}); + | --- + | ... +index = s:create_index('primary') + | --- + | ... + +ch = fiber.channel(1) + | --- + | ... +done = false + | --- + | ... + +function repl_f() local i = 0 while not done do s:replace({i, i}) fiber.sleep(0.001) i = i + 1 end ch:put(true) end + | --- + | ... +_ = fiber.create(repl_f) + | --- + | ... + +replica_set.join(test_run, 1) + | --- + | ... +test_run:cmd("switch replica1") + | --- + | - true + | ... + +test_run:cmd("switch default") + | --- + | - true + | ... +done = true + | --- + | ... +ch:get() + | --- + | - true + | ... + +errinj.set("ERRINJ_RELAY_FINAL_SLEEP", false) + | --- + | - ok + | ... +test_run:cmd("switch replica1") + | --- + | - true + | ... +test_run:cmd("setopt delimiter ';'") + | --- + | - true + | ... +function get_max_index_and_count() + return box.space.test.index.primary:max()[1], box.space.test.index.primary:count() +end; + | --- + | ... +max, count = 0, 0; + | --- + | ... +for i = 1, 100 do + max, count = box.atomic(get_max_index_and_count) + if max ~= count - 1 then + break + end +end; + | --- + | ... +-- Verify that at any moment max index is corresponding to amount of tuples, +-- which means that changes apply order is correct +max == count - 1 or {max, count - 1}; + | --- + | - true + | ... +test_run:cmd("setopt delimiter ''"); + | --- + | - true + | ... +test_run:cmd("switch default") + | --- + | - true + | ... + +replica_set.drop_all(test_run) + | --- + | ... +box.space.test:drop() + | --- + | ... +box.schema.user.revoke('guest', 'replication') + | --- + | ... diff --git a/test/replication/replica_apply_order.test.lua b/test/replication/replica_apply_order.test.lua new file mode 100644 index 0000000000000000000000000000000000000000..ba54ef8439de2ba3398d818ecd3f03ac2ed91af1 --- /dev/null +++ b/test/replication/replica_apply_order.test.lua @@ -0,0 +1,48 @@ +fiber = require('fiber') +env = require('test_run') +replica_set = require('fast_replica') +test_run = env.new() +engine = test_run:get_cfg('engine') + +errinj = box.error.injection +errinj.set("ERRINJ_RELAY_FINAL_SLEEP", true) + +box.schema.user.grant('guest', 'replication') +s = box.schema.space.create('test', {engine = engine}); +index = s:create_index('primary') + +ch = fiber.channel(1) +done = false + +function repl_f() local i = 0 while not done do s:replace({i, i}) fiber.sleep(0.001) i = i + 1 end ch:put(true) end +_ = fiber.create(repl_f) + +replica_set.join(test_run, 1) +test_run:cmd("switch replica1") + +test_run:cmd("switch default") +done = true +ch:get() + +errinj.set("ERRINJ_RELAY_FINAL_SLEEP", false) +test_run:cmd("switch replica1") +test_run:cmd("setopt delimiter ';'") +function get_max_index_and_count() + return box.space.test.index.primary:max()[1], box.space.test.index.primary:count() +end; +max, count = 0, 0; +for i = 1, 100 do + max, count = box.atomic(get_max_index_and_count) + if max ~= count - 1 then + break + end +end; +-- Verify that at any moment max index is corresponding to amount of tuples, +-- which means that changes apply order is correct +max == count - 1 or {max, count - 1}; +test_run:cmd("setopt delimiter ''"); +test_run:cmd("switch default") + +replica_set.drop_all(test_run) +box.space.test:drop() +box.schema.user.revoke('guest', 'replication') diff --git a/test/replication/suite.ini b/test/replication/suite.ini index 384dac677eabcb8e2c6715b05cd5d481e8d57233..ed1de31405e5f4b0bbc800eaa7f3f324fd64d1b0 100644 --- a/test/replication/suite.ini +++ b/test/replication/suite.ini @@ -12,7 +12,6 @@ long_run = prune.test.lua is_parallel = True pretest_clean = True fragile = errinj.test.lua ; gh-3870 - join_vclock.test.lua ; gh-4160 long_row_timeout.test.lua ; gh-4351 skip_conflict_row.test.lua ; gh-4457 sync.test.lua ; gh-3835 gh-3877