@@ -2,6 +2,7 @@ local fio = require('fio')
2
2
local clock = require (' clock' )
3
3
4
4
local t = require (' luatest' )
5
+ local luatest_capture = require (' luatest.capture' )
5
6
6
7
local helpers = require (' test.helper' )
7
8
@@ -26,6 +27,9 @@ pgroup.before_all(function(g)
26
27
g .cluster :server (' router' ).net_box :eval ([[
27
28
require('crud').cfg{ stats = true }
28
29
]] )
30
+ g .cluster :server (' router' ).net_box :eval ([[
31
+ require('crud.ratelimit').disable()
32
+ ]] )
29
33
end )
30
34
31
35
pgroup .after_all (function (g ) helpers .stop_cluster (g .cluster ) end )
@@ -37,14 +41,14 @@ pgroup.before_each(function(g)
37
41
end )
38
42
39
43
pgroup .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 } })
41
45
42
46
t .assert_equals (result , nil )
43
47
t .assert_str_contains (err .err , " Space \" non_existent_space\" doesn't exist" )
44
48
end
45
49
46
50
pgroup .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 } })
48
52
49
53
t .assert_equals (err , nil )
50
54
t .assert_equals (result , 0 )
@@ -69,7 +73,7 @@ pgroup.test_not_valid_operation = function(g)
69
73
}
70
74
71
75
local result , err = g .cluster .main_server .net_box :call (' crud.count' ,
72
- {' customers' , conditions }
76
+ {' customers' , conditions , { fullscan = true } }
73
77
)
74
78
75
79
t .assert_equals (result , nil )
@@ -89,6 +93,79 @@ pgroup.test_conditions_with_non_existed_field = function(g)
89
93
t .assert_equals (result , 0 )
90
94
end
91
95
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
+
92
169
pgroup .test_count_all = function (g )
93
170
-- let's insert five tuples on different replicasets
94
171
-- (two tuples on one replica and three on the other)
@@ -118,7 +195,7 @@ pgroup.test_count_all = function(g)
118
195
})
119
196
120
197
local result , err = g .cluster .main_server .net_box :call (' crud.count' ,
121
- {' customers' }
198
+ {' customers' , nil , { fullscan = true } }
122
199
)
123
200
124
201
t .assert_equals (err , nil )
@@ -154,7 +231,7 @@ pgroup.test_count_all_with_yield_every = function(g)
154
231
})
155
232
156
233
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 }}
158
235
)
159
236
160
237
t .assert_equals (err , nil )
@@ -190,7 +267,7 @@ pgroup.test_count_all_with_yield_every_0 = function(g)
190
267
})
191
268
192
269
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 }}
194
271
)
195
272
196
273
t .assert_equals (result , nil )
@@ -312,7 +389,7 @@ pgroup.test_ge_condition_with_index = function(g)
312
389
local expected_len = 3
313
390
314
391
local result , err = g .cluster .main_server .net_box :call (' crud.count' ,
315
- {' customers' , conditions }
392
+ {' customers' , conditions , { fullscan = true } }
316
393
)
317
394
318
395
t .assert_equals (err , nil )
@@ -354,7 +431,7 @@ pgroup.test_gt_condition_with_index = function(g)
354
431
local expected_len = 1
355
432
356
433
local result , err = g .cluster .main_server .net_box :call (' crud.count' ,
357
- {' customers' , conditions }
434
+ {' customers' , conditions , { fullscan = true } }
358
435
)
359
436
360
437
t .assert_equals (err , nil )
@@ -396,7 +473,7 @@ pgroup.test_le_condition_with_index = function(g)
396
473
local expected_len = 4
397
474
398
475
local result , err = g .cluster .main_server .net_box :call (' crud.count' ,
399
- {' customers' , conditions }
476
+ {' customers' , conditions , { fullscan = true } }
400
477
)
401
478
402
479
t .assert_equals (err , nil )
@@ -438,7 +515,7 @@ pgroup.test_lt_condition_with_index = function(g)
438
515
local expected_len = 2
439
516
440
517
local result , err = g .cluster .main_server .net_box :call (' crud.count' ,
441
- {' customers' , conditions }
518
+ {' customers' , conditions , { fullscan = true } }
442
519
)
443
520
444
521
t .assert_equals (err , nil )
@@ -543,6 +620,7 @@ pgroup.test_opts_not_damaged = function(g)
543
620
mode = ' read' ,
544
621
prefer_replica = false ,
545
622
balance = false ,
623
+ fullscan = true
546
624
}
547
625
local new_count_opts , err = g .cluster .main_server :eval ([[
548
626
local crud = require('crud')
@@ -586,7 +664,7 @@ pgroup.test_count_no_map_reduce = function(g)
586
664
local result , err = g .cluster .main_server .net_box :call (' crud.count' , {
587
665
' customers' ,
588
666
nil ,
589
- {bucket_id = 2804 , timeout = 1 },
667
+ {bucket_id = 2804 , timeout = 1 , fullscan = true },
590
668
})
591
669
t .assert_equals (err , nil )
592
670
t .assert_equals (result , 1 )
@@ -647,7 +725,7 @@ pgroup.test_count_timeout = function(g)
647
725
local begin = clock .proc ()
648
726
649
727
local result , err = g .cluster .main_server .net_box :call (' crud.count' ,
650
- {' customers' , conditions , {timeout = timeout }}
728
+ {' customers' , conditions , {timeout = timeout , fullscan = true }}
651
729
)
652
730
653
731
t .assert_equals (err , nil )
@@ -688,7 +766,7 @@ pgroup.test_composite_index = function(g)
688
766
}
689
767
690
768
-- 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 } )
692
770
693
771
t .assert_equals (err , nil )
694
772
t .assert_equals (result , 4 )
0 commit comments