Skip to content

Commit 94dce46

Browse files
committed
roles: change server address after reload
If the `listen` value was changed the server won't update it after config reload. After the patch this bug was fixed. Closes #209
1 parent 0d63047 commit 94dce46

File tree

4 files changed

+42
-0
lines changed

4 files changed

+42
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1313
### Fixed
1414

1515
- Removing the server if it is not in use (#212).
16+
- Changing server address if it was edited (#209).
1617

1718
## [1.7.0] - 2024-11-15
1819

roles/httpd.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ local function apply_http(name, node)
9999
httpd = httpd,
100100
routes = {},
101101
}
102+
elseif servers[name].host ~= host or servers[name].port ~= port then
103+
servers[name].httpd:stop()
104+
servers[name].httpd = http_server.new(host, port, parse_params(node))
105+
servers[name].httpd:start()
102106
end
103107
end
104108

test/integration/httpd_role_test.lua

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,3 +129,20 @@ g.test_stop_server_after_remove = function(cg)
129129

130130
t.assert_not(helpers.tcp_connection_exists('localhost', 13001))
131131
end
132+
133+
g.test_change_server_addr_on_the_run = function(cg)
134+
local resp = http_client:get('http://0.0.0.0:13001/ping')
135+
t.assert_equals(resp.status, 200, 'response not 200')
136+
t.assert_equals(resp.body, 'pong')
137+
138+
local cfg = table.deepcopy(config)
139+
cfg.groups['group-001'].replicasets['replicaset-001'].roles_cfg['roles.httpd'].additional.listen = 'localhost:13001'
140+
treegen.write_file(cg.server.chdir, 'config.yaml', yaml.encode(cfg))
141+
local _, err = cg.server:eval("require('config'):reload()")
142+
t.assert_not(err)
143+
144+
t.assert_not(helpers.tcp_connection_exists('0.0.0.0', 13001))
145+
resp = http_client:get('http://localhost:13001/ping')
146+
t.assert_equals(resp.status, 200, 'response not 200')
147+
t.assert_equals(resp.body, 'pong')
148+
end

test/unit/httpd_role_test.lua

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,3 +291,23 @@ g.test_stop_unusable_servers = function()
291291
t.assert(httpd_role.get_server())
292292
t.assert_equals(httpd_role.get_server('additional'))
293293
end
294+
295+
g.test_edit_server_address = function()
296+
local cfg = {
297+
[httpd_role.DEFAULT_SERVER_NAME] = {
298+
listen = 13001,
299+
},
300+
}
301+
302+
httpd_role.apply(cfg)
303+
local result = httpd_role.get_server()
304+
t.assert(result)
305+
t.assert_equals(result.port, cfg[httpd_role.DEFAULT_SERVER_NAME].listen)
306+
307+
cfg[httpd_role.DEFAULT_SERVER_NAME].listen = 13002
308+
309+
httpd_role.apply(cfg)
310+
result = httpd_role.get_server()
311+
t.assert(result)
312+
t.assert_equals(result.port, cfg[httpd_role.DEFAULT_SERVER_NAME].listen)
313+
end

0 commit comments

Comments
 (0)