forked from tarantool/tarantool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gh_8746_replica_transaction_boundary_test.lua
125 lines (115 loc) · 3.41 KB
/
gh_8746_replica_transaction_boundary_test.lua
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
local t = require('luatest')
local server = require('luatest.server')
local replica_set = require('luatest.replica_set')
local g = t.group('gh-8746-transaction-boundaries')
g.before_each(function(cg)
cg.replica_set = replica_set:new{}
end)
g.after_each(function(cg)
cg.replica_set:drop()
end)
local function prepare(cg)
cg.replica_set:start()
cg.master:exec(function()
box.ctl.wait_rw()
box.schema.space.create('test')
box.space.test:create_index('pk')
box.schema.space.create('loc', {is_local = true})
box.space.loc:create_index('pk')
end)
cg.replica:wait_for_vclock_of(cg.master)
cg.replica:exec(function()
box.space.test:on_replace(function(_, new)
box.space.loc:replace(new)
end)
end)
cg.master:exec(function()
box.space.test:replace{1}
end)
cg.replica:wait_for_vclock_of(cg.master)
end
g.before_test('test_replica_recovery', function(cg)
cg.master = cg.replica_set:build_and_add_server{
alias = 'master',
box_cfg = {
replication_timeout = 0.1,
},
}
cg.replica = cg.replica_set:build_and_add_server{
alias = 'replica',
box_cfg = {
read_only = true,
replication = server.build_listen_uri('master', cg.replica_set.id),
replication_timeout = 0.1,
},
}
end)
g.test_replica_recovery = function(cg)
prepare(cg)
cg.replica:restart()
cg.replica:wait_for_vclock_of(cg.master)
end
g.before_test('test_replication_to_master', function(cg)
cg.box_cfg = {
replication = {
server.build_listen_uri('master', cg.replica_set.id),
server.build_listen_uri('replica', cg.replica_set.id),
},
replication_timeout = 0.1,
}
cg.master = cg.replica_set:build_and_add_server{
alias = 'master',
box_cfg = cg.box_cfg,
}
cg.replica = cg.replica_set:build_and_add_server{
alias = 'replica',
box_cfg = cg.box_cfg,
}
end)
g.test_replication_to_master = function(cg)
prepare(cg)
cg.master:wait_for_vclock_of(cg.replica)
t.helpers.retrying({}, function()
cg.master:assert_follows_upstream(cg.replica:get_instance_id())
end)
end
g.before_test('test_replica_force_recovery', function(cg)
cg.master = cg.replica_set:build_and_add_server{
alias = 'master',
box_cfg = {
replication_timeout = 0.1,
},
}
cg.replica = cg.replica_set:build_and_add_server{
alias = 'replica',
box_cfg = {
read_only = true,
replication = server.build_listen_uri('master', cg.replica_set.id),
replication_timeout = 0.1,
force_recovery = true,
},
}
end)
g.test_replica_force_recovery = function(cg)
prepare(cg)
cg.master:exec(function()
box.begin()
box.space.test:replace{2}
box.space.test:replace{3}
box.commit()
end)
cg.replica:wait_for_vclock_of(cg.master)
cg.replica:exec(function()
box.cfg{read_only = false}
box.begin()
box.space.test:replace{4}
box.space.loc:replace{5}
box.space.test:replace{6}
box.commit()
end)
cg.replica:restart()
cg.replica:exec(function()
t.assert_equals(box.space.test:select{}, {{1}, {2}, {3}, {4}, {6}})
t.assert_equals(box.space.loc:select{}, {{1}, {2}, {3}, {4}, {5}, {6}})
end)
end