Skip to content

Commit

Permalink
tests(core): add test cases for simdjson yielding
Browse files Browse the repository at this point in the history
  • Loading branch information
chronolaw committed Jul 31, 2024
1 parent 3a1eeed commit 3c59341
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions spec/01-unit/31-simdjson/02-yield_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
local helpers = require("spec.helpers")


describe("[enable yield] ", function ()
local simdjson
local spy_ngx_sleep = spy.on(ngx, "sleep")

lazy_setup(function()
simdjson = require("resty.simdjson")
end)

lazy_teardown(function()
end)

it("when encoding", function()

local parser = simdjson.new(true)
assert(parser)

local str = parser:encode({ str = string.rep("a", 2100) })

parser:destroy()

assert(str)
assert(type(str) == "string")
assert.spy(spy_ngx_sleep).was_called(1)
end)


it("when decoding", function()

local a = {}
for i = 1, 1000 do
a[i] = i
end

local parser = simdjson.new(true)
assert(parser)

local obj = parser:decode("[" .. table.concat(a, ",") .. "]")

parser:destroy()

assert(obj)
assert(type(obj) == "table")
assert.spy(spy_ngx_sleep).was_called(2)
end)
end)

0 comments on commit 3c59341

Please sign in to comment.