@@ -2,6 +2,7 @@ local fio = require('fio')
22local clock = require (' clock' )
33
44local t = require (' luatest' )
5+ local luatest_capture = require (' luatest.capture' )
56
67local helpers = require (' test.helper' )
78
@@ -26,6 +27,9 @@ pgroup.before_all(function(g)
2627 g .cluster :server (' router' ).net_box :eval ([[
2728 require('crud').cfg{ stats = true }
2829 ]] )
30+ g .cluster :server (' router' ).net_box :eval ([[
31+ require('crud.ratelimit').disable()
32+ ]] )
2933end )
3034
3135pgroup .after_all (function (g ) helpers .stop_cluster (g .cluster ) end )
@@ -37,14 +41,14 @@ pgroup.before_each(function(g)
3741end )
3842
3943pgroup .test_count_non_existent_space = function (g )
40- local result , err = g .cluster .main_server .net_box :call (' crud.count' , {' non_existent_space' })
44+ local result , err = g .cluster .main_server .net_box :call (' crud.count' , {' non_existent_space' , nil , { fullscan = true } })
4145
4246 t .assert_equals (result , nil )
4347 t .assert_str_contains (err .err , " Space \" non_existent_space\" doesn't exist" )
4448end
4549
4650pgroup .test_count_empty_space = function (g )
47- local result , err = g .cluster .main_server .net_box :call (' crud.count' , {' customers' })
51+ local result , err = g .cluster .main_server .net_box :call (' crud.count' , {' customers' , nil , { fullscan = true } })
4852
4953 t .assert_equals (err , nil )
5054 t .assert_equals (result , 0 )
@@ -69,7 +73,7 @@ pgroup.test_not_valid_operation = function(g)
6973 }
7074
7175 local result , err = g .cluster .main_server .net_box :call (' crud.count' ,
72- {' customers' , conditions }
76+ {' customers' , conditions , { fullscan = true } }
7377 )
7478
7579 t .assert_equals (result , nil )
@@ -89,6 +93,79 @@ pgroup.test_conditions_with_non_existed_field = function(g)
8993 t .assert_equals (result , 0 )
9094end
9195
96+
97+ local count_safety_cases = {
98+ nil_and_nil_opts = {
99+ has_crit = true ,
100+ user_conditions = nil ,
101+ opts = nil ,
102+ },
103+ fullscan_false = {
104+ has_crit = true ,
105+ user_conditions = nil ,
106+ opts = {fullscan = false },
107+ },
108+ fullscan_true = {
109+ has_crit = false ,
110+ user_conditions = nil ,
111+ opts = {fullscan = true },
112+ },
113+ non_equal_conditions = {
114+ has_crit = true ,
115+ user_conditions = {
116+ {' >=' , ' last_name' , ' A' },
117+ {' <=' , ' last_name' , ' Z' },
118+ {' >' , ' age' , 20 },
119+ {' <' , ' age' , 30 },
120+ },
121+ opts = nil ,
122+ },
123+ equal_condition = {
124+ has_crit = false ,
125+ user_conditions = {
126+ {' >=' , ' last_name' , ' A' },
127+ {' <=' , ' last_name' , ' Z' },
128+ {' =' , ' age' , 25 },
129+ },
130+ opts = nil ,
131+ },
132+ equal_condition2 = {
133+ has_crit = false ,
134+ user_conditions = {
135+ {' >=' , ' last_name' , ' A' },
136+ {' <=' , ' last_name' , ' Z' },
137+ {' ==' , ' age' , 25 },
138+ },
139+ opts = nil ,
140+ },
141+ }
142+
143+ for name , case in pairs (count_safety_cases ) do
144+ local space = ' customers'
145+ local crit_log = " C> Potentially long count from space '" .. space .. " '"
146+ local test_name = (' test_count_safety_%s' ):format (name )
147+
148+ pgroup [test_name ] = function (g )
149+ local uc = case .user_conditions
150+ local opts = case .opts
151+ local capture = luatest_capture :new ()
152+ capture :enable ()
153+
154+ local _ , err = g .cluster .main_server .net_box :call (' crud.count' , {space , uc , opts })
155+ t .assert_equals (err , nil )
156+
157+ local captured = helpers .fflush_main_server_stdout (g .cluster , capture )
158+
159+ if case .has_crit then
160+ t .assert_str_contains (captured , crit_log )
161+ else
162+ t .assert_equals (string.find (captured , crit_log , 1 , true ), nil )
163+ end
164+
165+ capture :disable ()
166+ end
167+ end
168+
92169pgroup .test_count_all = function (g )
93170 -- let's insert five tuples on different replicasets
94171 -- (two tuples on one replica and three on the other)
@@ -118,7 +195,7 @@ pgroup.test_count_all = function(g)
118195 })
119196
120197 local result , err = g .cluster .main_server .net_box :call (' crud.count' ,
121- {' customers' }
198+ {' customers' , nil , { fullscan = true } }
122199 )
123200
124201 t .assert_equals (err , nil )
@@ -154,7 +231,7 @@ pgroup.test_count_all_with_yield_every = function(g)
154231 })
155232
156233 local result , err = g .cluster .main_server .net_box :call (' crud.count' ,
157- {' customers' , nil , {yield_every = 1 }}
234+ {' customers' , nil , {yield_every = 1 , fullscan = true }}
158235 )
159236
160237 t .assert_equals (err , nil )
@@ -190,7 +267,7 @@ pgroup.test_count_all_with_yield_every_0 = function(g)
190267 })
191268
192269 local result , err = g .cluster .main_server .net_box :call (' crud.count' ,
193- {' customers' , nil , {yield_every = 0 }}
270+ {' customers' , nil , {yield_every = 0 , fullscan = true }}
194271 )
195272
196273 t .assert_equals (result , nil )
@@ -312,7 +389,7 @@ pgroup.test_ge_condition_with_index = function(g)
312389 local expected_len = 3
313390
314391 local result , err = g .cluster .main_server .net_box :call (' crud.count' ,
315- {' customers' , conditions }
392+ {' customers' , conditions , { fullscan = true } }
316393 )
317394
318395 t .assert_equals (err , nil )
@@ -354,7 +431,7 @@ pgroup.test_gt_condition_with_index = function(g)
354431 local expected_len = 1
355432
356433 local result , err = g .cluster .main_server .net_box :call (' crud.count' ,
357- {' customers' , conditions }
434+ {' customers' , conditions , { fullscan = true } }
358435 )
359436
360437 t .assert_equals (err , nil )
@@ -396,7 +473,7 @@ pgroup.test_le_condition_with_index = function(g)
396473 local expected_len = 4
397474
398475 local result , err = g .cluster .main_server .net_box :call (' crud.count' ,
399- {' customers' , conditions }
476+ {' customers' , conditions , { fullscan = true } }
400477 )
401478
402479 t .assert_equals (err , nil )
@@ -438,7 +515,7 @@ pgroup.test_lt_condition_with_index = function(g)
438515 local expected_len = 2
439516
440517 local result , err = g .cluster .main_server .net_box :call (' crud.count' ,
441- {' customers' , conditions }
518+ {' customers' , conditions , { fullscan = true } }
442519 )
443520
444521 t .assert_equals (err , nil )
@@ -543,6 +620,7 @@ pgroup.test_opts_not_damaged = function(g)
543620 mode = ' read' ,
544621 prefer_replica = false ,
545622 balance = false ,
623+ fullscan = true
546624 }
547625 local new_count_opts , err = g .cluster .main_server :eval ([[
548626 local crud = require('crud')
@@ -586,7 +664,7 @@ pgroup.test_count_no_map_reduce = function(g)
586664 local result , err = g .cluster .main_server .net_box :call (' crud.count' , {
587665 ' customers' ,
588666 nil ,
589- {bucket_id = 2804 , timeout = 1 },
667+ {bucket_id = 2804 , timeout = 1 , fullscan = true },
590668 })
591669 t .assert_equals (err , nil )
592670 t .assert_equals (result , 1 )
@@ -647,7 +725,7 @@ pgroup.test_count_timeout = function(g)
647725 local begin = clock .proc ()
648726
649727 local result , err = g .cluster .main_server .net_box :call (' crud.count' ,
650- {' customers' , conditions , {timeout = timeout }}
728+ {' customers' , conditions , {timeout = timeout , fullscan = true }}
651729 )
652730
653731 t .assert_equals (err , nil )
@@ -688,7 +766,7 @@ pgroup.test_composite_index = function(g)
688766 }
689767
690768 -- no after
691- local result , err = g .cluster .main_server .net_box :call (' crud.count' , {' customers' , conditions })
769+ local result , err = g .cluster .main_server .net_box :call (' crud.count' , {' customers' , conditions }, { fullscan = true } )
692770
693771 t .assert_equals (err , nil )
694772 t .assert_equals (result , 4 )
0 commit comments