Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
picodata
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Container Registry
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
core
picodata
Commits
67e479a4
Verified
Commit
67e479a4
authored
3 years ago
by
Yaroslav Dynnikov
Browse files
Options
Downloads
Patches
Plain Diff
test: make luatest more concise
parent
f77edad0
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!53
test: raft log rollback
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
test/couple_test.lua
+2
-20
2 additions, 20 deletions
test/couple_test.lua
test/helper/picodata.lua
+55
-0
55 additions, 0 deletions
test/helper/picodata.lua
test/single_test.lua
+6
-31
6 additions, 31 deletions
test/single_test.lua
with
63 additions
and
51 deletions
test/couple_test.lua
+
2
−
20
View file @
67e479a4
...
...
@@ -39,28 +39,10 @@ end)
g
.
test
=
function
()
-- Speed up node election
g
.
cluster
.
i1
:
interact
({
msg_type
=
"MsgTimeoutNow"
,
to
=
1
,
from
=
0
,
})
h
.
retrying
({},
function
()
t
.
assert_equals
(
g
.
cluster
.
i2
:
connect
():
call
(
'picolib.raft_status'
),
{
id
=
2
,
leader_id
=
1
,
raft_state
=
"Follower"
,
}
)
end
)
g
.
cluster
.
i1
:
try_promote
()
t
.
assert_equals
(
g
.
cluster
.
i2
:
connect
():
call
(
'picolib.raft_propose_eval'
,
{
1
,
'_G.check = box.info.listen'
}
),
g
.
cluster
.
i2
:
raft_propose_eval
(
1
,
'_G.check = box.info.listen'
),
true
)
t
.
assert_equals
(
...
...
This diff is collapsed.
Click to expand it.
test/helper/picodata.lua
+
55
−
0
View file @
67e479a4
...
...
@@ -18,6 +18,7 @@ local Picodata = {
command
=
'target/debug/picodata'
,
process
=
nil
,
__type
=
'Picodata'
,
id
=
-
1
,
}
function
Picodata
:
inherit
(
object
)
...
...
@@ -82,6 +83,7 @@ function Picodata:start()
luatest
.
helpers
.
retrying
({},
function
()
self
:
connect
()
self
.
id
=
self
:
raft_status
().
id
end
)
end
...
...
@@ -124,6 +126,42 @@ function Picodata:stop()
self
.
process
=
nil
end
--- Get the status of raft node.
-- @function
-- @return {id = number, leader_id = number, state = string}
-- State can be one of "Follower", "Candidate", "Leader", "PreCandidate".
function
Picodata
:
raft_status
()
checks
(
'Picodata'
)
return
self
:
connect
():
call
(
'picolib.raft_status'
)
end
--- Assert raft status matches expectations.
-- @function
-- @tparam string raft_state
-- @tparam[opt] number leader_id
function
Picodata
:
assert_raft_status
(
raft_state
,
leader_id
)
checks
(
'Picodata'
,
'string'
,
'?number'
)
return
luatest
.
assert_covers
(
self
:
raft_status
(),
{
leader_id
=
leader_id
,
raft_state
=
raft_state
,
}
)
end
--- Propose Lua code evaluation on every node in cluster.
-- @tparam number timeout
-- @tparam string code
-- @treturn boolean whether proposal was committed on the current node.
function
Picodata
:
raft_propose_eval
(
timeout
,
code
)
checks
(
'Picodata'
,
'number'
,
'string'
)
return
self
:
connect
():
call
(
'picolib.raft_propose_eval'
,
{
timeout
,
code
}
)
end
function
Picodata
:
interact
(
opts
)
checks
(
'Picodata'
,
{
-- See picolib/traft/row/message.rs
...
...
@@ -156,4 +194,21 @@ function Picodata:interact(opts)
})
end
--- Try forcing leader election when previous leader is dead.
-- Wait for the node becoming a leader.
-- Raise an exception if promotion fails.
function
Picodata
:
try_promote
()
checks
(
'Picodata'
)
self
:
interact
({
msg_type
=
"MsgTimeoutNow"
,
to
=
self
.
id
,
from
=
0
,
})
return
luatest
.
helpers
.
retrying
({},
function
()
self
:
assert_raft_status
(
"Leader"
,
self
.
id
)
end
)
end
return
Picodata
This diff is collapsed.
Click to expand it.
test/single_test.lua
+
6
−
31
View file @
67e479a4
...
...
@@ -22,51 +22,26 @@ g.after_all(function()
end
)
g
.
test
=
function
()
local
conn
=
g
.
node
:
connect
(
)
g
.
node
:
assert_raft_status
(
"Follower"
)
t
.
assert_equals
(
conn
:
call
(
'picolib.raft_status'
),
{
id
=
1
,
leader_id
=
0
,
raft_state
=
"Follower"
,
}
)
t
.
assert_equals
(
conn
:
call
(
'picolib.raft_propose_eval'
,
{
1
,
'return'
}),
g
.
node
:
raft_propose_eval
(
1
,
'return'
),
false
-- No leader is elected yet
)
-- Speed up node election
g
.
node
:
interact
({
msg_type
=
"MsgTimeoutNow"
,
to
=
1
,
from
=
0
,
})
h
.
retrying
({},
function
()
t
.
assert_equals
(
conn
:
call
(
'picolib.raft_status'
),
{
id
=
1
,
leader_id
=
1
,
raft_state
=
"Leader"
,
}
)
end
)
g
.
node
:
try_promote
()
t
.
assert_equals
(
conn
:
call
(
'picolib.
raft_propose_eval
'
,
{
0
,
'return'
}
),
g
.
node
:
raft_propose_eval
(
0
,
'return'
),
false
-- Timeout
)
t
.
assert_equals
(
conn
:
call
(
'picolib.
raft_propose_eval
'
,
{
1
,
'_G.success = true'
}
),
g
.
node
:
raft_propose_eval
(
1
,
'_G.success = true'
),
true
)
t
.
assert_equals
(
conn
:
eval
(
'return success'
),
g
.
node
:
connect
()
:
eval
(
'return success'
),
true
)
end
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment