Skip to content

Commit

Permalink
Workaround plan unit tests
Browse files Browse the repository at this point in the history
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
  • Loading branch information
DifferentialOrange committed Nov 24, 2021
1 parent 408d1cf commit 377603f
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 0 deletions.
15 changes: 15 additions & 0 deletions test/helper.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 10 additions & 0 deletions test/unit/select_dropped_indexes_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
10 changes: 10 additions & 0 deletions test/unit/select_executor_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand Down
10 changes: 10 additions & 0 deletions test/unit/select_filters_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
10 changes: 10 additions & 0 deletions test/unit/select_filters_uuid_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
10 changes: 10 additions & 0 deletions test/unit/select_plan_bad_indexes_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
10 changes: 10 additions & 0 deletions test/unit/select_plan_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 377603f

Please sign in to comment.