From 597a4f669db3b7e074d3aa5455cc6816c2e9017d Mon Sep 17 00:00:00 2001 From: Georgy Moiseev Date: Thu, 18 Jan 2024 10:38:33 +0300 Subject: [PATCH] test: do not rely on replication in more read cases Some read cases were missing in #404, #406 and #408 test stabilization commits. This patch updates missing read cases. 1. https://github.com/tarantool/crud/actions/runs/7322196516/job/19943422319 Follows #404 Part of #412 Part of #415 --- test/doc/playground_test.lua | 6 +- test/integration/borders_test.lua | 80 +++++++++++++++--------- test/integration/count_test.lua | 36 +++++++---- test/integration/pairs_test.lua | 2 +- test/integration/select_test.lua | 8 ++- test/integration/stats_test.lua | 43 +++++++------ test/integration/truncate_test.lua | 12 +++- test/integration/updated_schema_test.lua | 32 ++++++---- 8 files changed, 140 insertions(+), 79 deletions(-) diff --git a/test/doc/playground_test.lua b/test/doc/playground_test.lua index 0fa8ad5a..9a3bf951 100644 --- a/test/doc/playground_test.lua +++ b/test/doc/playground_test.lua @@ -61,7 +61,7 @@ end local cases = { test_select_customers = { - request = "crud.select('customers', {{'<=', 'age', 35}}, {first = 10})", + request = "crud.select('customers', {{'<=', 'age', 35}}, {first = 10, mode = 'write'})", retval_1 = { metadata = { {name = 'id', type = 'unsigned'}, @@ -79,7 +79,7 @@ local cases = { } }, test_select_developers = { - request = "crud.select('developers', nil, {first = 6})", + request = "crud.select('developers', nil, {first = 6, mode = 'write'})", retval_1 = { metadata = { {name = 'id', type = 'unsigned'}, @@ -117,7 +117,7 @@ local cases = { test_error = { request = [[ do - local res, err = crud.select('non_existent', nil, {first = 10}) + local res, err = crud.select('non_existent', nil, {first = 10, mode = 'write'}) return res, err and err.err or nil end ]], diff --git a/test/integration/borders_test.lua b/test/integration/borders_test.lua index 52a5412e..511b4662 100644 --- a/test/integration/borders_test.lua +++ b/test/integration/borders_test.lua @@ -26,17 +26,21 @@ end) pgroup.test_non_existent_space = function(g) -- min - local result, err = g.cluster.main_server.net_box:call( - 'crud.min', {'non_existent_space'} - ) + local result, err = g.cluster.main_server.net_box:call('crud.min', { + 'non_existent_space', + nil, + {mode = 'write'}, + }) t.assert_equals(result, nil) t.assert_str_contains(err.err, "Space \"non_existent_space\" doesn't exist") -- max - local result, err = g.cluster.main_server.net_box:call( - 'crud.max', {'non_existent_space'} - ) + local result, err = g.cluster.main_server.net_box:call('crud.max', { + 'non_existent_space', + nil, + {mode = 'write'}, + }) t.assert_equals(result, nil) t.assert_str_contains(err.err, "Space \"non_existent_space\" doesn't exist") @@ -44,31 +48,39 @@ end pgroup.test_non_existent_index = function(g) -- min - local result, err = g.cluster.main_server.net_box:call( - 'crud.min', {'customers', 'non_existent_index'} - ) + local result, err = g.cluster.main_server.net_box:call('crud.min', { + 'customers', + 'non_existent_index', + {mode = 'write'}, + }) t.assert_equals(result, nil) t.assert_str_contains(err.err, "Index \"non_existent_index\" of space \"customers\" doesn't exist") - local result, err = g.cluster.main_server.net_box:call( - 'crud.min', {'customers', 13} - ) + local result, err = g.cluster.main_server.net_box:call('crud.min', { + 'customers', + 13, + {mode = 'write'}, + }) t.assert_equals(result, nil) t.assert_str_contains(err.err, "Index \"13\" of space \"customers\" doesn't exist") -- max - local result, err = g.cluster.main_server.net_box:call( - 'crud.max', {'customers', 'non_existent_index'} - ) + local result, err = g.cluster.main_server.net_box:call('crud.max', { + 'customers', + 'non_existent_index', + {mode = 'write'}, + }) t.assert_equals(result, nil) t.assert_str_contains(err.err, "Index \"non_existent_index\" of space \"customers\" doesn't exist") - local result, err = g.cluster.main_server.net_box:call( - 'crud.max', {'customers', 13} - ) + local result, err = g.cluster.main_server.net_box:call('crud.max', { + 'customers', + 13, + {mode = 'write'}, + }) t.assert_equals(result, nil) t.assert_str_contains(err.err, "Index \"13\" of space \"customers\" doesn't exist") @@ -76,33 +88,41 @@ end pgroup.test_empty_space = function(g) -- min - local result, err = g.cluster.main_server.net_box:call( - 'crud.min', {'customers'} - ) + local result, err = g.cluster.main_server.net_box:call('crud.min', { + 'customers', + nil, + {mode = 'write'}, + }) t.assert_equals(err, nil) t.assert_equals(#result.rows, 0) -- min by age index with fields - local result, err = g.cluster.main_server.net_box:call( - 'crud.min', {'customers', 'age_index', {fields = {'name'}}} - ) + local result, err = g.cluster.main_server.net_box:call('crud.min', { + 'customers', + 'age_index', + {fields = {'name'}, mode = 'write'}, + }) t.assert_equals(err, nil) t.assert_equals(#result.rows, 0) -- max - local result, err = g.cluster.main_server.net_box:call( - 'crud.max', {'customers'} - ) + local result, err = g.cluster.main_server.net_box:call('crud.max', { + 'customers', + nil, + {mode = 'write'}, + }) t.assert_equals(err, nil) t.assert_equals(#result.rows, 0) -- max by age index with fields - local result, err = g.cluster.main_server.net_box:call( - 'crud.max', {'customers', 'age_index', {fields = {'name'}}} - ) + local result, err = g.cluster.main_server.net_box:call('crud.max', { + 'customers', + 'age_index', + {fields = {'name'}, mode = 'write'}, + }) t.assert_equals(err, nil) t.assert_equals(#result.rows, 0) diff --git a/test/integration/count_test.lua b/test/integration/count_test.lua index 6d1668de..7eecfc3f 100644 --- a/test/integration/count_test.lua +++ b/test/integration/count_test.lua @@ -33,14 +33,22 @@ pgroup.before_each(function(g) end) pgroup.test_count_non_existent_space = function(g) - local result, err = g.cluster.main_server.net_box:call('crud.count', {'non_existent_space', nil, {fullscan = true}}) + local result, err = g.cluster.main_server.net_box:call('crud.count', { + 'non_existent_space', + nil, + {fullscan = true, mode = 'write'}, + }) t.assert_equals(result, nil) t.assert_str_contains(err.err, "Space \"non_existent_space\" doesn't exist") end pgroup.test_count_empty_space = function(g) - local result, err = g.cluster.main_server.net_box:call('crud.count', {'customers', nil, {fullscan = true}}) + local result, err = g.cluster.main_server.net_box:call('crud.count', { + 'customers', + nil, + {fullscan = true, mode = 'write'}, + }) t.assert_equals(err, nil) t.assert_equals(result, 0) @@ -51,9 +59,11 @@ pgroup.test_not_valid_value_type = function(g) {'==', 'id', 'not_number'} } - local result, err = g.cluster.main_server.net_box:call('crud.count', - {'customers', conditions} - ) + local result, err = g.cluster.main_server.net_box:call('crud.count', { + 'customers', + conditions, + {mode = 'write'}, + }) t.assert_equals(result, nil) t.assert_str_contains(err.err, "Supplied key type of part 0 does not match index part type: expected unsigned") @@ -64,9 +74,11 @@ pgroup.test_not_valid_operation = function(g) {{}, 'id', 5} } - local result, err = g.cluster.main_server.net_box:call('crud.count', - {'customers', conditions, {fullscan = true}} - ) + local result, err = g.cluster.main_server.net_box:call('crud.count', { + 'customers', + conditions, + {fullscan = true, mode = 'write'}, + }) t.assert_equals(result, nil) t.assert_str_contains(err.err, "Failed to parse conditions") @@ -77,9 +89,11 @@ pgroup.test_conditions_with_non_existed_field = function(g) {'==', 'non_existed_field', 'value'} } - local result, err = g.cluster.main_server.net_box:call('crud.count', - {'customers', conditions} - ) + local result, err = g.cluster.main_server.net_box:call('crud.count', { + 'customers', + conditions, + {mode = 'write'}, + }) t.assert_equals(err, nil) t.assert_equals(result, 0) diff --git a/test/integration/pairs_test.lua b/test/integration/pairs_test.lua index d5f850ba..9c3c2bd5 100644 --- a/test/integration/pairs_test.lua +++ b/test/integration/pairs_test.lua @@ -419,7 +419,7 @@ pgroup.test_pairs_partial_result = function(g) local conditions, fields = ... local tuples = {} - for _, tuple in crud.pairs('customers', conditions, {fields = fields}) do + for _, tuple in crud.pairs('customers', conditions, {fields = fields, mode = 'write'}) do table.insert(tuples, tuple) end diff --git a/test/integration/select_test.lua b/test/integration/select_test.lua index 70b834e9..9373ac64 100644 --- a/test/integration/select_test.lua +++ b/test/integration/select_test.lua @@ -40,7 +40,9 @@ end) pgroup.test_non_existent_space = function(g) -- insert local obj, err = g.cluster.main_server.net_box:call('crud.select', { - 'non_existent_space', nil, {fullscan = true}, + 'non_existent_space', + nil, + {fullscan = true, mode = 'write'}, }) t.assert_equals(obj, nil) @@ -49,7 +51,9 @@ end pgroup.test_select_no_index = function(g) local obj, err = g.cluster.main_server.net_box:call('crud.select', { - 'no_index_space', nil, {fullscan = true}, + 'no_index_space', + nil, + {fullscan = true, mode = 'write'}, }) t.assert_equals(obj, nil) diff --git a/test/integration/stats_test.lua b/test/integration/stats_test.lua index c54ff47c..222be1fd 100644 --- a/test/integration/stats_test.lua +++ b/test/integration/stats_test.lua @@ -157,9 +157,10 @@ local eval = { pairs = [[ local space_name = select(1, ...) local conditions = select(2, ...) + local opts = select(3, ...) local result = {} - for _, v in crud.pairs(space_name, conditions, { batch_size = 1 }) do + for _, v in crud.pairs(space_name, conditions, opts) do table.insert(result, v) end @@ -169,8 +170,9 @@ local eval = { pairs_pcall = [[ local space_name = select(1, ...) local conditions = select(2, ...) + local opts = select(3, ...) - local _, err = pcall(crud.pairs, space_name, conditions, { batch_size = 1 }) + local _, err = pcall(crud.pairs, space_name, conditions, opts) return nil, tostring(err) ]], @@ -217,17 +219,17 @@ local simple_operation_cases = { }, get = { func = 'crud.get', - args = { space_name, { 12 } }, + args = { space_name, { 12 }, {mode = 'write'}, }, op = 'get', }, select = { func = 'crud.select', - args = { space_name, {{ '==', 'id_index', 3 }} }, + args = { space_name, {{ '==', 'id_index', 3 }}, {mode = 'write'}, }, op = 'select', }, pairs = { eval = eval.pairs, - args = { space_name, {{ '==', 'id_index', 3 }} }, + args = { space_name, {{ '==', 'id_index', 3 }}, {batch_size = 1, mode = 'write'}, }, op = 'select', }, replace = { @@ -336,17 +338,17 @@ local simple_operation_cases = { }, count = { func = 'crud.count', - args = { space_name, {{ '==', 'id_index', 3 }} }, + args = { space_name, {{ '==', 'id_index', 3 }}, {mode = 'write'}, }, op = 'count', }, min = { func = 'crud.min', - args = { space_name }, + args = { space_name, nil, {mode = 'write'}, }, op = 'borders', }, max = { func = 'crud.max', - args = { space_name }, + args = { space_name, nil, {mode = 'write'}, }, op = 'borders', }, insert_error = { @@ -375,19 +377,19 @@ local simple_operation_cases = { }, get_error = { func = 'crud.get', - args = { space_name, { 'id' } }, + args = { space_name, { 'id' }, {mode = 'write'}, }, op = 'get', expect_error = true, }, select_error = { func = 'crud.select', - args = { space_name, {{ '==', 'id_index', 'sdf' }} }, + args = { space_name, {{ '==', 'id_index', 'sdf' }}, {mode = 'write'}, }, op = 'select', expect_error = true, }, pairs_error = { eval = eval.pairs, - args = { space_name, {{ '%=', 'id_index', 'sdf' }} }, + args = { space_name, {{ '%=', 'id_index', 'sdf' }}, {batch_size = 1, mode = 'write'}, }, op = 'select', expect_error = true, pcall = true, @@ -454,19 +456,19 @@ local simple_operation_cases = { }, count_error = { func = 'crud.count', - args = { space_name, {{ '==', 'id_index', 'sdf' }} }, + args = { space_name, {{ '==', 'id_index', 'sdf' }}, {mode = 'write'}, }, op = 'count', expect_error = true, }, min_error = { func = 'crud.min', - args = { space_name, 'badindex' }, + args = { space_name, 'badindex', {mode = 'write'}, }, op = 'borders', expect_error = true, }, max_error = { func = 'crud.max', - args = { space_name, 'badindex' }, + args = { space_name, 'badindex', {mode = 'write'}, }, op = 'borders', expect_error = true, }, @@ -508,6 +510,7 @@ local select_cases = { select_by_primary_index = { func = 'crud.select', conditions = {{ '==', 'id_index', 3 }}, + opts = {mode = 'write'}, map_reduces = 0, tuples_fetched = 1, tuples_lookup = 1, @@ -515,6 +518,7 @@ local select_cases = { select_by_secondary_index = { func = 'crud.select', conditions = {{ '==', 'age_index', 46 }}, + opts = {mode = 'write'}, map_reduces = 1, tuples_fetched = 1, tuples_lookup = 1, @@ -522,14 +526,15 @@ local select_cases = { select_full_scan = { func = 'crud.select', conditions = {{ '>', 'id_index', 0 }, { '==', 'city', 'Kyoto' }}, + opts = {fullscan = true, mode = 'write'}, map_reduces = 1, tuples_fetched = 0, tuples_lookup = 4, - opts = {fullscan = true}, }, pairs_by_primary_index = { eval = eval.pairs, conditions = {{ '==', 'id_index', 3 }}, + opts = {batch_size = 1, mode = 'write'}, map_reduces = 0, tuples_fetched = 1, -- Since batch_size == 1, extra lookup is generated with @@ -539,6 +544,7 @@ local select_cases = { pairs_by_secondary_index = { eval = eval.pairs, conditions = {{ '==', 'age_index', 46 }}, + opts = {batch_size = 1, mode = 'write'}, map_reduces = 1, tuples_fetched = 1, -- Since batch_size == 1, extra lookup is generated with @@ -548,6 +554,7 @@ local select_cases = { pairs_full_scan = { eval = eval.pairs, conditions = {{ '>', 'id_index', 0 }, { '==', 'city', 'Kyoto' }}, + opts = {batch_size = 1, mode = 'write'}, map_reduces = 1, tuples_fetched = 0, tuples_lookup = 4, @@ -746,9 +753,9 @@ for name, case in pairs(select_cases) do -- Call operation. local _, err if case.eval ~= nil then - _, err = g.router:eval(case.eval, { space_name, case.conditions }) + _, err = g.router:eval(case.eval, { space_name, case.conditions, case.opts }) else - _, err = g.router:call(case.func, { space_name, case.conditions }) + _, err = g.router:call(case.func, { space_name, case.conditions, case.opts }) end t.assert_equals(err, nil) @@ -1091,7 +1098,7 @@ local function check_updated_per_call(g) local map_reduces_before = find_obs('tnt_crud_map_reduces', details_labels, metrics_before) local case = select_cases['select_by_secondary_index'] - local _, err = g.router:call(case.func, { space_name, case.conditions }) + local _, err = g.router:call(case.func, { space_name, case.conditions, case.opts }) t.assert_equals(err, nil) local metrics_after = get_metrics(g) diff --git a/test/integration/truncate_test.lua b/test/integration/truncate_test.lua index b766dd96..873427c7 100644 --- a/test/integration/truncate_test.lua +++ b/test/integration/truncate_test.lua @@ -51,7 +51,11 @@ pgroup.test_truncate = function(g) table.sort(customers, function(obj1, obj2) return obj1.id < obj2.id end) - local result, err = g.cluster.main_server.net_box:call('crud.select', {'customers', nil, {fullscan = true}}) + local result, err = g.cluster.main_server.net_box:call('crud.select', { + 'customers', + nil, + {fullscan = true, mode = 'write'}, + }) t.assert_equals(err, nil) t.assert_gt(#result.rows, 0) @@ -59,7 +63,11 @@ pgroup.test_truncate = function(g) t.assert_equals(err, nil) t.assert_equals(result, true) - local result, err = g.cluster.main_server.net_box:call('crud.select', {'customers', nil, {fullscan = true}}) + local result, err = g.cluster.main_server.net_box:call('crud.select', { + 'customers', + nil, + {fullscan = true, mode = 'write'}, + }) t.assert_equals(err, nil) t.assert_equals(#result.rows, 0) end diff --git a/test/integration/updated_schema_test.lua b/test/integration/updated_schema_test.lua index 8edff056..775a1dca 100644 --- a/test/integration/updated_schema_test.lua +++ b/test/integration/updated_schema_test.lua @@ -715,9 +715,11 @@ pgroup.test_borders_value_index_added = function(g) for _, border_func_name in ipairs({'crud.max', 'crud.min'}) do -- non-existent space err - local obj, err = g.cluster.main_server.net_box:call( - border_func_name, {'customers', 'value_index'} - ) + local obj, err = g.cluster.main_server.net_box:call(border_func_name, { + 'customers', + 'value_index', + {mode = 'write'}, + }) t.assert_equals(obj, nil) t.assert_is_not(err, nil) @@ -731,9 +733,11 @@ pgroup.test_borders_value_index_added = function(g) for _, border_func_name in ipairs({'crud.max', 'crud.min'}) do -- check that schema changes were applied - local obj, err = g.cluster.main_server.net_box:call( - border_func_name, {'customers', 'value_index'} - ) + local obj, err = g.cluster.main_server.net_box:call(border_func_name, { + 'customers', + 'value_index', + {mode = 'write'}, + }) t.assert_is_not(obj, nil) t.assert_equals(err, nil) @@ -756,9 +760,11 @@ pgroup.test_alter_index_parts = function(g) end -- Check sort order before alter - local result, err = g.cluster.main_server.net_box:call( - 'crud.select', {'customers', {{'>=', 'number_value_index', {0, "0"}}}, {fullscan = true}} - ) + local result, err = g.cluster.main_server.net_box:call('crud.select', { + 'customers', + {{'>=', 'number_value_index', {0, "0"}}}, + {fullscan = true, mode = 'write'}, + }) t.assert_equals(err, nil) t.assert_equals(#result.rows, 10) @@ -777,9 +783,11 @@ pgroup.test_alter_index_parts = function(g) fiber.sleep(1) -- Sort order should be new - local result, err = g.cluster.main_server.net_box:call( - 'crud.select', {'customers', {{'>=', 'number_value_index', {"0", 0}}}, {fullscan = true}} - ) + local result, err = g.cluster.main_server.net_box:call('crud.select', { + 'customers', + {{'>=', 'number_value_index', {"0", 0}}}, + {fullscan = true, mode = 'write'}, + }) t.assert_equals(err, nil) t.assert_equals(#result.rows, 10)