Skip to content

Commit 377603f

Browse files
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
1 parent 408d1cf commit 377603f

7 files changed

+75
-0
lines changed

test/helper.lua

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,4 +332,19 @@ function helpers.update_cache(cluster, space_name)
332332
]], {space_name})
333333
end
334334

335+
function helpers.set_sharding_key_module_dummy()
336+
package.loaded['crud.common.sharding_key'] = {
337+
fetch_on_router = function(_) return nil; end
338+
}
339+
340+
-- Reload 'crud.select.plan' so it recursively
341+
-- reload 'crud.common.sharding_key'.
342+
package.loaded['crud.select.plan'] = nil
343+
end
344+
345+
function helpers.unset_sharding_key_module_dummy()
346+
package.loaded['crud.common.sharding_key'] = nil
347+
package.loaded['crud.select.plan'] = nil
348+
end
349+
335350
return helpers

test/unit/select_dropped_indexes_test.lua

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,20 @@ g.before_all = function()
6666

6767
-- We need this check to make sure that test actually covers a problem.
6868
t.assert_not_equals(#box.space.customers.index, table.maxn(box.space.customers.index))
69+
70+
-- Workaround for plan failing to build without cofigured vshard.router.
71+
-- crud.common.call function 'any' fails to use vshard.router.routeall()
72+
-- which leads to fail of crud.common.sharding_key function 'fetch_on_router'
73+
-- in critical section of 'reentrant_fetch' in the same module.
74+
helpers.set_sharding_key_module_dummy()
75+
select_plan = require('crud.select.plan')
6976
end
7077

7178
g.after_all = function()
7279
box.space.customers:drop()
80+
81+
-- Unset workaround from g.before_all.
82+
helpers.unset_sharding_key_module_dummy()
7383
end
7484

7585
g.test_before_dropped_index_field = function()

test/unit/select_executor_test.lua

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@ g.before_all = function()
5858
})
5959

6060
crud.init_storage()
61+
62+
-- Workaround for plan failing to build without cofigured vshard.router.
63+
-- crud.common.call function 'any' fails to use vshard.router.routeall()
64+
-- which leads to fail of crud.common.sharding_key function 'fetch_on_router'
65+
-- in critical section of 'reentrant_fetch' in the same module.
66+
helpers.set_sharding_key_module_dummy()
67+
select_plan = require('crud.select.plan')
6168
end
6269

6370
g.after_each(function()
@@ -66,6 +73,9 @@ end)
6673

6774
g.after_all(function()
6875
box.space.customers:drop()
76+
77+
-- Unset workaround from g.before_all.
78+
helpers.unset_sharding_key_module_dummy()
6979
end)
7080

7181
g.test_one_condition_no_index = function()

test/unit/select_filters_test.lua

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,21 @@ g.before_all = function()
8181
if_not_exists = true,
8282
})
8383
end
84+
85+
-- Workaround for plan failing to build without cofigured vshard.router.
86+
-- crud.common.call function 'any' fails to use vshard.router.routeall()
87+
-- which leads to fail of crud.common.sharding_key function 'fetch_on_router'
88+
-- in critical section of 'reentrant_fetch' in the same module.
89+
helpers.set_sharding_key_module_dummy()
90+
select_plan = require('crud.select.plan')
8491
end
8592

8693
g.after_all(function()
8794
box.space.customers:drop()
8895
box.space.cars:drop()
96+
97+
-- Unset workaround from g.before_all.
98+
helpers.unset_sharding_key_module_dummy()
8999
end)
90100

91101
g.test_empty_conditions = function()

test/unit/select_filters_uuid_test.lua

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,20 @@ g.before_all = function()
3838
if_not_exists = true,
3939
})
4040
end
41+
42+
-- Workaround for plan failing to build without cofigured vshard.router.
43+
-- crud.common.call function 'any' fails to use vshard.router.routeall()
44+
-- which leads to fail of crud.common.sharding_key function 'fetch_on_router'
45+
-- in critical section of 'reentrant_fetch' in the same module.
46+
helpers.set_sharding_key_module_dummy()
47+
select_plan = require('crud.select.plan')
4148
end
4249

4350
g.after_all(function()
4451
box.space.customers:drop()
52+
53+
-- Unset workaround from g.before_all.
54+
helpers.unset_sharding_key_module_dummy()
4555
end)
4656

4757
g.test_parse = function()

test/unit/select_plan_bad_indexes_test.lua

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,20 @@ g.before_all = function()
6565
unique = false,
6666
if_not_exists = true,
6767
})
68+
69+
-- Workaround for plan failing to build without cofigured vshard.router.
70+
-- crud.common.call function 'any' fails to use vshard.router.routeall()
71+
-- which leads to fail of crud.common.sharding_key function 'fetch_on_router'
72+
-- in critical section of 'reentrant_fetch' in the same module.
73+
helpers.set_sharding_key_module_dummy()
74+
select_plan = require('crud.select.plan')
6875
end
6976

7077
g.after_all = function()
7178
box.space.customers:drop()
79+
80+
-- Unset workaround from g.before_all.
81+
helpers.unset_sharding_key_module_dummy()
7282
end
7383

7484
g.test_select_all_bad_primary = function()

test/unit/select_plan_test.lua

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,20 @@ g.before_all = function()
6464
parts = { {field = 'bucket_id'} },
6565
if_not_exists = true,
6666
})
67+
68+
-- Workaround for plan failing to build without cofigured vshard.router.
69+
-- crud.common.call function 'any' fails to use vshard.router.routeall()
70+
-- which leads to fail of crud.common.sharding_key function 'fetch_on_router'
71+
-- in critical section of 'reentrant_fetch' in the same module.
72+
helpers.set_sharding_key_module_dummy()
73+
select_plan = require('crud.select.plan')
6774
end
6875

6976
g.after_all(function()
7077
box.space.customers:drop()
78+
79+
-- Unset workaround from g.before_all.
80+
helpers.unset_sharding_key_module_dummy()
7181
end)
7282

7383
g.test_indexed_field = function()

0 commit comments

Comments
 (0)