File: gh-4231-box-execute-locking.test.lua

package info (click to toggle)
tarantool 2.6.0-1.4
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 85,412 kB
  • sloc: ansic: 513,775; cpp: 69,493; sh: 25,650; python: 19,190; perl: 14,973; makefile: 4,178; yacc: 1,329; sql: 1,074; pascal: 620; ruby: 190; awk: 18; lisp: 7
file content (69 lines) | stat: -rwxr-xr-x 2,077 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env tarantool

-- gh-4231: run box_load_and_execute() (it is box.execute value
-- before box will be loaded) in several fibers in parallel and
-- ensure that it returns correct results (i.e. that the function
-- waits until box will be fully configured).
--
-- The test can be configured to call box.execute() from a fiber
-- instead of box_load_and_execute(): it can be done either via
-- test-run using confguration feature or using an argument when
-- the test is invoked directly.

local fiber = require('fiber')
local tap = require('tap')

-- Determine configuration.
local conf = 'box_load_and_execute'
local ok, test_run = pcall(require, 'test_run')
if ok then
    test_run = test_run.new()
    conf = test_run:get_cfg('conf')
elseif #arg >= 1 then
    conf = arg[1]
end
assert(conf == 'box_load_and_execute' or
       conf == 'box.execute')

local box_load_and_execute = box.execute
local fiber_count = 10
local results = fiber.channel(fiber_count)

local function select_from_vindex()
    local box_execute_func =
        conf == 'box_load_and_execute' and box_load_and_execute or
        conf == 'box.execute' and box.execute or
        function() return false end

    local res = box_execute_func('SELECT * FROM "_vindex"')
    results:put(res)
end

local test = tap.test('gh-4231-box-execute-locking')
test:diag('configuration: %s', conf)

test:plan(fiber_count)

local exp_metadata = {
    {name = 'id',    type = 'unsigned'},
    {name = 'iid',   type = 'unsigned'},
    {name = 'name',  type = 'string'},
    {name = 'type',  type = 'string'},
    {name = 'opts',  type = 'map'},
    {name = 'parts', type = 'array'},
}

for _ = 1, fiber_count do
    fiber.create(select_from_vindex)
end
for i = 1, fiber_count do
    local res = results:get()
    test:test(('result %d'):format(i), function(test)
        test:plan(2)
        test:is_deeply(res.metadata, exp_metadata, 'verify metadata')
        local rows_is_ok = type(res.rows) == 'table' and #res.rows > 0
        test:ok(rows_is_ok, 'verify rows')
    end)
end

os.exit(test:check() and 0 or 1)