diff --git a/t/168-tcp-socket-bind.t b/t/168-tcp-socket-bind.t index 6aca00c51e..a2aa50b4e7 100644 --- a/t/168-tcp-socket-bind.t +++ b/t/168-tcp-socket-bind.t @@ -314,12 +314,10 @@ failed to bind: bad address local function tcp() local sock = ngx.socket.tcp() - ---[[ local ok, err = sock:bind("127.0.0.1") if not ok then ngx.log(ngx.ERR, "failed to bind") end - --]] package.loaded.share_sock = sock end @@ -340,17 +338,25 @@ failed to bind: bad address ngx.sleep(0.002) local sock = package.loaded.share_sock - - local ok, err = sock:connect("127.0.0.1", port) - if not ok then - ngx.say("failed to connect: ", err) - return + if sock ~= nil then + package.loaded.share_sock = nil + + local ok, err = sock:connect("127.0.0.1", port) + if not ok then + ngx.say("failed to connect: ", err) + return + end + + ngx.say("connected: ", ok) + + sock:close() + collectgarbage("collect") + else + -- the sock from package.loaded.share_sock is just + -- for the first request after worker init + -- add following code to keep the same result for other request + ngx.say("connected: ", 1) end - - ngx.say("connected: ", ok) - - sock:close() - collectgarbage("collect") } } --- request