Make integration/unit tests deterministic, isolated, and robust against async timing and ordering.
Checklist
pwait_until/assert.eventually, don’t add extra per-assert timeouts unless you truly need nested waits.teardown()/cleanup stops every started component and closes clients even if earlier assertions fail.Example pattern (Lua)
describe("readiness", function()
lazy_setup(function()
assert(start_kong_dp())
end)
lazy_teardown(function()
-- always stop what we started
assert(helpers.stop_kong("serve_dp"))
end)
it("transitions to ready", function()
local res = helpers.http_client("127.0.0.1", tcp_status_port):get("/status/ready")
assert.res_status(503, res) -- assert initial state
assert.with_timeout(30).eventually(function()
local r = helpers.http_client("127.0.0.1", tcp_status_port):get("/status/ready")
assert.res_status(200, r)
end)
end)
end)
Apply this standard whenever tests touch CP/DP sync, rate limiting/period counters, metrics/log convergence, or any configuration that can be mutated across tests.
Enter the URL of a public GitHub repository