Skip to content

Commit a01dfa5

Browse files
Add quantile fiber test
1 parent fd21ba0 commit a01dfa5

File tree

2 files changed

+5
-18
lines changed

2 files changed

+5
-18
lines changed

metrics/quantile.lua

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,8 @@ function stream:merge(samples, len)
134134
local i = 1
135135
local r = 0
136136
for z = 1, len do
137-
if i % 1000 == 0 then
138-
fiber.yield()
137+
if i % 1000 == 0 then
138+
fiber.yield()
139139
end
140140
local sample = samples[z-1]
141141
for j = i, s.l_len do
@@ -259,6 +259,8 @@ end
259259

260260
-- Insert inserts v into the stream.
261261
function quantile.Insert(stream_obj, v)
262+
assert(stream_obj.b_len < ffi.sizeof(stream_obj.b)/ffi.sizeof('sample'), 'Array index out of bound ' .. stream_obj.b_len .. ' ' .. ffi.sizeof(stream_obj.b)/ffi.sizeof('sample'))
263+
262264
stream_obj.b[stream_obj.b_len] = v
263265
stream_obj.b_len = stream_obj.b_len + 1
264266
stream_obj.compress_cnt = stream_obj.compress_cnt + 1

test/quantile_fiber_test.lua

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,5 @@ local q = quantile.NewTargeted({[0.5]=0.01, [0.9]=0.01, [0.99]=0.01})
99

1010

1111
g.test_fiber = function()
12-
for i=1,1e6 do quantile.Insert(q, math.random(1)) end
13-
14-
local fs = {}
15-
for i=1,200 do
16-
local f = fiber.new(function()
17-
for i=1,1e3 do quantile.Insert(q, math.random(1000)) end
18-
end)
19-
f:set_joinable(true)
20-
table.insert(fs, f)
21-
end
22-
23-
for i=1,1e3 do quantile.Insert(q, math.random(1000)) end
24-
25-
for _, f in ipairs(fs) do
26-
f:join()
27-
end
12+
for i=1,1000 do quantile.Insert(q, math.random(1)) end
2813
end

0 commit comments

Comments
 (0)