File tree Expand file tree Collapse file tree 6 files changed +66
-5
lines changed Expand file tree Collapse file tree 6 files changed +66
-5
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
12
12
13
13
### Fixed
14
14
15
+ - Removing the server if it is not in use (#212 ).
16
+
15
17
## [ 1.7.0] - 2024-11-15
16
18
17
19
The release introduces a TLS support.
Original file line number Diff line number Diff line change @@ -130,9 +130,21 @@ M.apply = function(conf)
130
130
-- a meaningful error if something goes wrong.
131
131
M .validate (conf )
132
132
133
+ local actual_servers = {}
134
+
133
135
for name , node in pairs (conf or {}) do
136
+ actual_servers [name ] = true
137
+
134
138
apply_http (name , node )
135
139
end
140
+
141
+ -- Stop server if it is not using anymore.
142
+ for name , server in pairs (servers ) do
143
+ if actual_servers [name ] == nil then
144
+ server .httpd :stop ()
145
+ servers [name ] = nil
146
+ end
147
+ end
136
148
end
137
149
138
150
M .stop = function ()
Original file line number Diff line number Diff line change @@ -130,4 +130,12 @@ helpers.update_lua_env_variables = function(server)
130
130
ROOT .. ' /.rocks/lib/tarantool/?/?.so;'
131
131
end
132
132
133
+ helpers .tcp_connection_exists = function (host , port )
134
+ local tcp = socket .tcp ()
135
+ tcp :settimeout (0.3 )
136
+ local ok , _ = tcp :connect (host , port )
137
+ tcp :close ()
138
+ return ok
139
+ end
140
+
133
141
return helpers
Original file line number Diff line number Diff line change @@ -115,3 +115,17 @@ g.test_httpd_role_usage = function(cg)
115
115
' return require("test.mocks.mock_role").get_server_port(2)'
116
116
), 13001 )
117
117
end
118
+
119
+ g .test_stop_server_after_remove = function (cg )
120
+ local resp = http_client :get (' http://localhost:13001/ping' )
121
+ t .assert_equals (resp .status , 200 , ' response not 200' )
122
+ t .assert_equals (resp .body , ' pong' )
123
+
124
+ local cfg = table .deepcopy (config )
125
+ cfg .groups [' group-001' ].replicasets [' replicaset-001' ].roles_cfg [' roles.httpd' ].additional = nil
126
+ treegen .write_file (cg .server .chdir , ' config.yaml' , yaml .encode (cfg ))
127
+ local _ , err = cg .server :eval (" require('config'):reload()" )
128
+ t .assert_not (err )
129
+
130
+ t .assert_not (helpers .tcp_connection_exists (' localhost' , 13001 ))
131
+ end
Original file line number Diff line number Diff line change @@ -8,11 +8,13 @@ M.apply = function(conf)
8
8
for _ , server in pairs (conf ) do
9
9
servers [server .id ] = require (' roles.httpd' ).get_server (server .name )
10
10
11
- servers [server .id ]:route ({
12
- path = ' /ping' ,
13
- }, function (tx )
14
- return tx :render ({text = ' pong' })
15
- end )
11
+ if servers [server .id ] ~= nil then
12
+ servers [server .id ]:route ({
13
+ path = ' /ping' ,
14
+ }, function (tx )
15
+ return tx :render ({text = ' pong' })
16
+ end )
17
+ end
16
18
end
17
19
end
18
20
Original file line number Diff line number Diff line change @@ -268,3 +268,26 @@ g['test_get_server_bad_type'] = function()
268
268
t .assert_not (ok )
269
269
t .assert_str_contains (res , ' ?string expected, got table' )
270
270
end
271
+
272
+ g .test_stop_unusable_servers = function ()
273
+ local cfg = {
274
+ [httpd_role .DEFAULT_SERVER_NAME ] = {
275
+ listen = 13001 ,
276
+ },
277
+ additional = {
278
+ listen = 13002 ,
279
+ },
280
+ }
281
+
282
+ httpd_role .apply (cfg )
283
+ for name , body in pairs (cfg ) do
284
+ local res = httpd_role .get_server (name )
285
+ t .assert (res )
286
+ t .assert_equals (res .port , body .listen )
287
+ end
288
+
289
+ cfg .additional = nil
290
+ httpd_role .apply (cfg )
291
+ t .assert (httpd_role .get_server ())
292
+ t .assert_equals (httpd_role .get_server (' additional' ))
293
+ end
You can’t perform that action at this time.
0 commit comments