From 377603fe247779b0f86e2be64a7a2cb4601b8cbe Mon Sep 17 00:00:00 2001 From: Georgy Moiseev Date: Wed, 24 Nov 2021 15:42:50 +0300 Subject: [PATCH] Workaround plan unit tests Unit tests for plan module fails to run without cofigured vshard.router after introduction of improved sharding key extraction in 408d1cf. This patch sets up dummy 'crud.common.sharding_key' modules for plan unit tests. Follows up #213 --- test/helper.lua | 15 +++++++++++++++ test/unit/select_dropped_indexes_test.lua | 10 ++++++++++ test/unit/select_executor_test.lua | 10 ++++++++++ test/unit/select_filters_test.lua | 10 ++++++++++ test/unit/select_filters_uuid_test.lua | 10 ++++++++++ test/unit/select_plan_bad_indexes_test.lua | 10 ++++++++++ test/unit/select_plan_test.lua | 10 ++++++++++ 7 files changed, 75 insertions(+) diff --git a/test/helper.lua b/test/helper.lua index 913aa56ca..2e423ff3b 100644 --- a/test/helper.lua +++ b/test/helper.lua @@ -332,4 +332,19 @@ function helpers.update_cache(cluster, space_name) ]], {space_name}) end +function helpers.set_sharding_key_module_dummy() + package.loaded['crud.common.sharding_key'] = { + fetch_on_router = function(_) return nil; end + } + + -- Reload 'crud.select.plan' so it recursively + -- reload 'crud.common.sharding_key'. + package.loaded['crud.select.plan'] = nil +end + +function helpers.unset_sharding_key_module_dummy() + package.loaded['crud.common.sharding_key'] = nil + package.loaded['crud.select.plan'] = nil +end + return helpers diff --git a/test/unit/select_dropped_indexes_test.lua b/test/unit/select_dropped_indexes_test.lua index 8012ae683..4e29cadbb 100644 --- a/test/unit/select_dropped_indexes_test.lua +++ b/test/unit/select_dropped_indexes_test.lua @@ -66,10 +66,20 @@ g.before_all = function() -- We need this check to make sure that test actually covers a problem. t.assert_not_equals(#box.space.customers.index, table.maxn(box.space.customers.index)) + + -- Workaround for plan failing to build without cofigured vshard.router. + -- crud.common.call function 'any' fails to use vshard.router.routeall() + -- which leads to fail of crud.common.sharding_key function 'fetch_on_router' + -- in critical section of 'reentrant_fetch' in the same module. + helpers.set_sharding_key_module_dummy() + select_plan = require('crud.select.plan') end g.after_all = function() box.space.customers:drop() + + -- Unset workaround from g.before_all. + helpers.unset_sharding_key_module_dummy() end g.test_before_dropped_index_field = function() diff --git a/test/unit/select_executor_test.lua b/test/unit/select_executor_test.lua index a9977cd43..0044f8928 100644 --- a/test/unit/select_executor_test.lua +++ b/test/unit/select_executor_test.lua @@ -58,6 +58,13 @@ g.before_all = function() }) crud.init_storage() + + -- Workaround for plan failing to build without cofigured vshard.router. + -- crud.common.call function 'any' fails to use vshard.router.routeall() + -- which leads to fail of crud.common.sharding_key function 'fetch_on_router' + -- in critical section of 'reentrant_fetch' in the same module. + helpers.set_sharding_key_module_dummy() + select_plan = require('crud.select.plan') end g.after_each(function() @@ -66,6 +73,9 @@ end) g.after_all(function() box.space.customers:drop() + + -- Unset workaround from g.before_all. + helpers.unset_sharding_key_module_dummy() end) g.test_one_condition_no_index = function() diff --git a/test/unit/select_filters_test.lua b/test/unit/select_filters_test.lua index 38ad38596..be4dc2111 100644 --- a/test/unit/select_filters_test.lua +++ b/test/unit/select_filters_test.lua @@ -81,11 +81,21 @@ g.before_all = function() if_not_exists = true, }) end + + -- Workaround for plan failing to build without cofigured vshard.router. + -- crud.common.call function 'any' fails to use vshard.router.routeall() + -- which leads to fail of crud.common.sharding_key function 'fetch_on_router' + -- in critical section of 'reentrant_fetch' in the same module. + helpers.set_sharding_key_module_dummy() + select_plan = require('crud.select.plan') end g.after_all(function() box.space.customers:drop() box.space.cars:drop() + + -- Unset workaround from g.before_all. + helpers.unset_sharding_key_module_dummy() end) g.test_empty_conditions = function() diff --git a/test/unit/select_filters_uuid_test.lua b/test/unit/select_filters_uuid_test.lua index 256e7ba1e..e7c812641 100644 --- a/test/unit/select_filters_uuid_test.lua +++ b/test/unit/select_filters_uuid_test.lua @@ -38,10 +38,20 @@ g.before_all = function() if_not_exists = true, }) end + + -- Workaround for plan failing to build without cofigured vshard.router. + -- crud.common.call function 'any' fails to use vshard.router.routeall() + -- which leads to fail of crud.common.sharding_key function 'fetch_on_router' + -- in critical section of 'reentrant_fetch' in the same module. + helpers.set_sharding_key_module_dummy() + select_plan = require('crud.select.plan') end g.after_all(function() box.space.customers:drop() + + -- Unset workaround from g.before_all. + helpers.unset_sharding_key_module_dummy() end) g.test_parse = function() diff --git a/test/unit/select_plan_bad_indexes_test.lua b/test/unit/select_plan_bad_indexes_test.lua index d0c392e94..c3174dded 100644 --- a/test/unit/select_plan_bad_indexes_test.lua +++ b/test/unit/select_plan_bad_indexes_test.lua @@ -65,10 +65,20 @@ g.before_all = function() unique = false, if_not_exists = true, }) + + -- Workaround for plan failing to build without cofigured vshard.router. + -- crud.common.call function 'any' fails to use vshard.router.routeall() + -- which leads to fail of crud.common.sharding_key function 'fetch_on_router' + -- in critical section of 'reentrant_fetch' in the same module. + helpers.set_sharding_key_module_dummy() + select_plan = require('crud.select.plan') end g.after_all = function() box.space.customers:drop() + + -- Unset workaround from g.before_all. + helpers.unset_sharding_key_module_dummy() end g.test_select_all_bad_primary = function() diff --git a/test/unit/select_plan_test.lua b/test/unit/select_plan_test.lua index cc0dee3ff..70328b69d 100644 --- a/test/unit/select_plan_test.lua +++ b/test/unit/select_plan_test.lua @@ -64,10 +64,20 @@ g.before_all = function() parts = { {field = 'bucket_id'} }, if_not_exists = true, }) + + -- Workaround for plan failing to build without cofigured vshard.router. + -- crud.common.call function 'any' fails to use vshard.router.routeall() + -- which leads to fail of crud.common.sharding_key function 'fetch_on_router' + -- in critical section of 'reentrant_fetch' in the same module. + helpers.set_sharding_key_module_dummy() + select_plan = require('crud.select.plan') end g.after_all(function() box.space.customers:drop() + + -- Unset workaround from g.before_all. + helpers.unset_sharding_key_module_dummy() end) g.test_indexed_field = function()