Skip to content

Commit

Permalink
Add tests for server's stop
Browse files Browse the repository at this point in the history
Tests were added in attempt to reproduce #76.
  • Loading branch information
ligurio committed Feb 3, 2022
1 parent 8e24d13 commit 8b885a0
Showing 1 changed file with 79 additions and 0 deletions.
79 changes: 79 additions & 0 deletions test/integration/http_server_action_test.lua
@@ -0,0 +1,79 @@
local fio = require('fio')
local fiber = require('fiber')
local socket = require('socket')
local t = require('luatest')
local http_client = require('http.client')
local http_server = require('http.server')

local helpers = require('test.helpers')

local g = t.group()

g.before_test('test_stop_basic', function()
g.httpd = helpers.cfgserv()
g.httpd:start()
end)

g.before_test('test_stop_with_open_connection', function()
g.httpd = helpers.cfgserv()
g.httpd:start()
end)

g.after_test('test_stop_basic', function()
helpers.retrying({}, function()
local conn = socket.tcp_connect(helpers.base_host, helpers.base_port)
return conn ~= nil
end)
fio.rmdir(helpers.path)
end)

g.after_test('test_stop_with_open_connection', function()
helpers.retrying({}, function()
local r = http_client.request('GET', helpers.base_uri)
return r == nil
end)
fio.rmdir(helpers.path)
end)

g.test_stop_basic = function()
local httpd = g.httpd
httpd:route({
method = 'GET',
path = '/test/json',
}, 'test#json')

local resp = httpd:stop()
t.assert_not_equals(resp, nil)
t.assert_type(resp, 'table')
end

g.test_stop_with_open_connection = function()
local httpd = g.httpd
httpd:route({
method = 'GET',
path = '/test/json',
}, 'test#json')

-- Open connection to the web server.
local resp = http_client.get(helpers.base_uri)
t.assert_not_equals(resp, nil)

-- Stop server.
httpd:stop()
t.assert_not_equals(resp, nil)
t.assert_type(resp, 'table')
end

g.test_stop_with_custom_handler = function()
local httpd = http_server.new('0.0.0.0', 8080)
httpd:route({
path = '/'
}, function ()
return {
status = 200, body = 'hello'
}
end)
httpd:start()
fiber.sleep(0.1)
httpd:stop()
end

0 comments on commit 8b885a0

Please sign in to comment.