diff --git a/spec/01-unit/31-simdjson/02-yield_spec.lua b/spec/01-unit/31-simdjson/02-yield_spec.lua new file mode 100644 index 000000000000..da334fe27fc8 --- /dev/null +++ b/spec/01-unit/31-simdjson/02-yield_spec.lua @@ -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)