Skip to content
Snippets Groups Projects
Commit fb9c8b32 authored by Alexandr Lyapunov's avatar Alexandr Lyapunov Committed by Roman Tsisyk
Browse files

vinyl: improve tx_serial.test

The test now generetes lua code that reproduces found problem.
The generated code is saved in log.
parent 0137219d
No related branches found
No related tags found
No related merge requests found
......@@ -44,6 +44,15 @@ stmts = {}
errors = {}
---
...
initial_data = {}
---
...
initial_repro = ""
---
...
repro = ""
---
...
ops = {'begin', 'commit', 'select', 'replace', 'upsert', 'delete'}
---
...
......@@ -113,6 +122,14 @@ function prepare()
s2:delete{i}
end
end
initial_data = s1:select{}
initial_repro = ""
initial_repro = initial_repro .. "s = box.schema.space.create('test', {engine = 'vinyl', if_not_exists = true})\n"
initial_repro = initial_repro .. "i1 = s:create_index('test', {parts = {1, 'uint'}, if_not_exists = true})\n"
initial_repro = initial_repro .. "txn_proxy = require('txn_proxy')\n"
for _,tuple in pairs(initial_data) do
initial_repro = initial_repro .. "s:replace{" .. tuple[1] .. ", " .. tuple[2] .. "} "
end
end;
---
...
......@@ -120,6 +137,7 @@ function apply(t, k, op)
local tx = txs[t]
local v = nil
local k = k
local repro = nil
if op == 'begin' then
if tx.started then
table.insert(errors, "assert #1")
......@@ -127,6 +145,8 @@ function apply(t, k, op)
tx.started = true
tx.con:begin()
k = nil
repro = "c" .. t .. " = txn_proxy.new() c" .. t .. ":begin()"
repro = "p(\"c" .. t .. ":begin()\") " .. repro
elseif op == 'commit' then
if tx.ended or not tx.started then
table.insert(errors, "assert #2")
......@@ -144,21 +164,31 @@ function apply(t, k, op)
end
end
k = nil
repro = "c" .. t .. ":commit()"
repro = "p(\"" .. repro .. "\", " .. repro .. ", s:select{})"
elseif op == 'select' then
v = tx.con('s1:select{'..k..'}')
repro = "c" .. t .. "('s:select{" .. k .. "}')"
repro = "p(\"" .. repro .. "\", " .. repro .. ")"
elseif op == 'replace' then
v = get_unique_value()
tx.con('s1:replace{'..k..','..v..'}')
tx.num_writes = tx.num_writes + 1
repro = "c" .. t .. "('s:replace{" .. k .. ", " .. v .. "}')"
repro = "p(\"" .. repro .. "\", " .. repro .. ")"
elseif op == 'upsert' then
v = math.random(100)
tx.con('s1:upsert({'..k..','..v..'}, {{"+", 2,'..v..'}})')
tx.num_writes = tx.num_writes + 1
repro = "c" .. t .. "('s:upsert({" .. k .. ", " .. v .. "}, {{\\'+\\', 2, " .. v .. "}})')"
repro = "p(\"" .. repro .. "\", " .. repro .. ")"
elseif op == 'delete' then
tx.con('s1:delete{'..k..'}')
tx.num_writes = tx.num_writes + 1
repro = "c" .. t .. "('s:delete{" .. k .. "}')"
repro = "p(\"" .. repro .. "\", " .. repro .. ")"
end
table.insert(stmts, {t=t, k=k, op=op, v=v})
table.insert(stmts, {t=t, k=k, op=op, v=v, repro=repro})
end;
---
...
......@@ -234,6 +264,7 @@ end;
---
...
function check()
local had_errors = (errors[1] ~= nil)
for i=1,num_tx do
if txs[i].read_only then
if txs[i].conflicted then
......@@ -261,6 +292,15 @@ function check()
table.insert(errors, "not valid read view " .. i)
end
end
if errors[1] and not had_errors then
repro = "p(\"" .. errors[1] .. "\")"
repro = repro .. "\n" .. initial_repro
repro = repro .. "\n" .. "p(\"" .. initial_repro .. "\")"
repro = repro .. "\n" .. '----------------------'
for _,stmt in ipairs(stmts) do
repro = repro .. "\n" .. stmt.repro
end
end
end;
---
...
......@@ -281,6 +321,9 @@ errors
---
- []
...
if repro ~= "" then print(repro) io.flush() end
---
...
s1:drop()
---
...
......
......@@ -26,6 +26,9 @@ order_of_commit = {}
num_committed = 0
stmts = {}
errors = {}
initial_data = {}
initial_repro = ""
repro = ""
ops = {'begin', 'commit', 'select', 'replace', 'upsert', 'delete'}
test_run:cmd("setopt delimiter ';'")
......@@ -89,12 +92,21 @@ function prepare()
s2:delete{i}
end
end
initial_data = s1:select{}
initial_repro = ""
initial_repro = initial_repro .. "s = box.schema.space.create('test', {engine = 'vinyl', if_not_exists = true})\n"
initial_repro = initial_repro .. "i1 = s:create_index('test', {parts = {1, 'uint'}, if_not_exists = true})\n"
initial_repro = initial_repro .. "txn_proxy = require('txn_proxy')\n"
for _,tuple in pairs(initial_data) do
initial_repro = initial_repro .. "s:replace{" .. tuple[1] .. ", " .. tuple[2] .. "} "
end
end;
function apply(t, k, op)
local tx = txs[t]
local v = nil
local k = k
local repro = nil
if op == 'begin' then
if tx.started then
table.insert(errors, "assert #1")
......@@ -102,6 +114,8 @@ function apply(t, k, op)
tx.started = true
tx.con:begin()
k = nil
repro = "c" .. t .. " = txn_proxy.new() c" .. t .. ":begin()"
repro = "p(\"c" .. t .. ":begin()\") " .. repro
elseif op == 'commit' then
if tx.ended or not tx.started then
table.insert(errors, "assert #2")
......@@ -119,21 +133,31 @@ function apply(t, k, op)
end
end
k = nil
repro = "c" .. t .. ":commit()"
repro = "p(\"" .. repro .. "\", " .. repro .. ", s:select{})"
elseif op == 'select' then
v = tx.con('s1:select{'..k..'}')
repro = "c" .. t .. "('s:select{" .. k .. "}')"
repro = "p(\"" .. repro .. "\", " .. repro .. ")"
elseif op == 'replace' then
v = get_unique_value()
tx.con('s1:replace{'..k..','..v..'}')
tx.num_writes = tx.num_writes + 1
repro = "c" .. t .. "('s:replace{" .. k .. ", " .. v .. "}')"
repro = "p(\"" .. repro .. "\", " .. repro .. ")"
elseif op == 'upsert' then
v = math.random(100)
tx.con('s1:upsert({'..k..','..v..'}, {{"+", 2,'..v..'}})')
tx.num_writes = tx.num_writes + 1
repro = "c" .. t .. "('s:upsert({" .. k .. ", " .. v .. "}, {{\\'+\\', 2, " .. v .. "}})')"
repro = "p(\"" .. repro .. "\", " .. repro .. ")"
elseif op == 'delete' then
tx.con('s1:delete{'..k..'}')
tx.num_writes = tx.num_writes + 1
repro = "c" .. t .. "('s:delete{" .. k .. "}')"
repro = "p(\"" .. repro .. "\", " .. repro .. ")"
end
table.insert(stmts, {t=t, k=k, op=op, v=v})
table.insert(stmts, {t=t, k=k, op=op, v=v, repro=repro})
end;
function generate_random_operation()
......@@ -204,6 +228,7 @@ function check_rdonly_possibility()
end;
function check()
local had_errors = (errors[1] ~= nil)
for i=1,num_tx do
if txs[i].read_only then
if txs[i].conflicted then
......@@ -231,6 +256,15 @@ function check()
table.insert(errors, "not valid read view " .. i)
end
end
if errors[1] and not had_errors then
repro = "p(\"" .. errors[1] .. "\")"
repro = repro .. "\n" .. initial_repro
repro = repro .. "\n" .. "p(\"" .. initial_repro .. "\")"
repro = repro .. "\n" .. '----------------------'
for _,stmt in ipairs(stmts) do
repro = repro .. "\n" .. stmt.repro
end
end
end;
for i = 1, num_tests do
......@@ -244,6 +278,7 @@ end;
test_run:cmd("setopt delimiter ''");
errors
if repro ~= "" then print(repro) io.flush() end
s1:drop()
s2:drop()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment