Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(test): eliminate duplicate mig http_server #10867

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,57 +3,10 @@ local cjson = require "cjson"
local tablex = require "pl.tablex"

local uh = require "spec/upgrade_helpers"
local helpers = require "spec.helpers"
local http_server = helpers.http_server

local HTTP_PORT = 29100

-- Copied from 3.x helpers.lua

local function http_server(port, opts)
local threads = require "llthreads2.ex"
opts = opts or {}
local thread = threads.new(
{
function(port, opts)
local socket = require "socket"
local server = assert(socket.tcp())
server:settimeout(opts.timeout or 60)
assert(server:setoption('reuseaddr', true))
assert(server:bind("*", port))
assert(server:listen())
local client = assert(server:accept())

local lines = {}
local line, err
repeat
line, err = client:receive("*l")
if err then
break
else
table.insert(lines, line)
end
until line == ""

if #lines > 0 and lines[1] == "GET /delay HTTP/1.0" then
ngx.sleep(2)
end

if err then
server:close()
error(err)
end

local body, _ = client:receive("*a")

client:send("HTTP/1.1 200 OK\r\nConnection: close\r\n\r\n")
client:close()
server:close()

return lines, body
end
},
port, opts)
return thread:start()
end
local HTTP_PORT = helpers.get_available_port()

describe("http-log plugin migration", function()

Expand Down Expand Up @@ -97,12 +50,12 @@ describe("http-log plugin migration", function()

uh.send_proxy_get_request()

local ok, headers = thread:join()
assert.truthy(ok)
local ok, lines = thread:join()
assert.truthy(ok, lines)

-- verify that the log HTTP request had the configured header
local idx = tablex.find(headers, custom_header_name .. ": " .. custom_header_content)
assert.not_nil(idx, headers)
local idx = tablex.find(lines, custom_header_name .. ": " .. custom_header_content)
assert.not_nil(idx, lines)
end)

uh.new_after_finish("has updated http-log configuration", function ()
Expand Down