Skip to content

Commit

Permalink
test: add test with a wrong behaviour of GC finalizer
Browse files Browse the repository at this point in the history
`http.client` has an incorrect behaviour: HTTP-client object could be
GC-collected before GC-collecting an active chunked HTTP request. The
patch adds a test with an incorrect behaviour. Following commits will
fix this behaviour.

Needed for tarantool#9453

NO_CHANGELOG=testing
NO_DOC=testing
  • Loading branch information
ligurio committed Dec 7, 2023
1 parent 81cd95c commit 2f46052
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions test/app-luatest/http_client_test.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
local popen = require('popen')
local client = require('http.client')
local json = require('json')
local fiber = require('fiber')
Expand Down Expand Up @@ -1352,3 +1353,36 @@ g.test_http_client_io_post_parts = function(cg)
t.assert_equals(io.status, 200, 'io')
t.assert_equals(io.reason, 'Ok', '200 - Ok')
end

-- Read from ph:stderr and fail if it doesn't contain a `pattern'.
local function grep_stderr_or_fail(ph, pattern)
local output = ''
t.helpers.retrying({}, function()
local chunk = ph:read({timeout = 0.05, stderr = true})
if chunk ~= nil then
output = output .. chunk
end
t.assert_str_contains(output, pattern)
end)
end

g.test_http_client_gc_finalizer_gh_9453 = function(cg)
local tarantool_exe = arg[-1]
local lua_code = [[local url = '%s'
local c = require('http.client').new()
local r = c:get(url, {chunked = true})
c = nil
collectgarbage()
collectgarbage()
r:read(1)]]
local ph = popen.new({ tarantool_exe, '-e', lua_code:format(cg.url) },
{ stderr = popen.opts.PIPE })
t.assert(ph)

-- Wait for the process startup.
grep_stderr_or_fail(ph, "IllegalParams: io: request must be io")

ph:close()
end

0 comments on commit 2f46052

Please sign in to comment.