Skip to content

Commit 5d0d65e

Browse files
committed
tests: added time limit to base32 random tests
1 parent 909694a commit 5d0d65e

1 file changed

Lines changed: 18 additions & 10 deletions

File tree

t/base32.t

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -281,18 +281,26 @@ decode: MMMMMM: invalid input
281281
282282
=== TEST 5: random tests
283283
--- lua
284-
for _ = 1, 1e6 do
285-
local size = math.random(1, 20)
286-
local buf = table.new(size, 0)
287-
for i = 1, size do
288-
buf[i] = math.random(33, 126)
284+
local start = ngx.now()
285+
while ture do
286+
for _ = 1, 1000 do
287+
local size = math.random(1, 20)
288+
local buf = table.new(size, 0)
289+
for i = 1, size do
290+
buf[i] = math.random(33, 126)
291+
end
292+
293+
local raw = string.char(unpack(buf))
294+
local encoded = base_encoding.encode_base32(raw)
295+
if base_encoding.decode_base32(encoded) ~= raw then
296+
ngx.say("failed case: ", raw)
297+
return
298+
end
289299
end
290300
291-
local raw = string.char(unpack(buf))
292-
local encoded = base_encoding.encode_base32(raw)
293-
if base_encoding.decode_base32(encoded) ~= raw then
294-
ngx.say("failed case: ", raw)
295-
return
301+
ngx.update_time()
302+
if ngx.now() - start > 3 then
303+
break
296304
end
297305
end
298306
ngx.say("ok")

0 commit comments

Comments
 (0)