Skip to content

Commit

Permalink
chore(test): eliminate duplicate mig http_server
Browse files Browse the repository at this point in the history
Partial fix of KAG-1148
  • Loading branch information
StarlightIbuki committed May 16, 2023
1 parent 77e4e12 commit 9285f9c
Showing 1 changed file with 6 additions and 53 deletions.
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()
local ok, lines = thread:join()
assert.truthy(ok)

-- 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

0 comments on commit 9285f9c

Please sign in to comment.