File: replica_apply_order.test.lua

package info (click to toggle)
tarantool 2.6.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 85,364 kB
  • sloc: ansic: 513,760; cpp: 69,489; sh: 25,650; python: 19,190; perl: 14,973; makefile: 4,173; yacc: 1,329; sql: 1,074; pascal: 620; ruby: 190; awk: 18; lisp: 7
file content (48 lines) | stat: -rw-r--r-- 1,376 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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')