Software /
code /
prosody
Annotate
plugins/mod_debug_reset.lua @ 13028:b2e6a175537d
mod_debug_reset: Don't delay operations until next tick
For some unknown reason, this was required with the old mock util.time
functions prior to 012d6e7b723a.
After 012d6e7b723a, it breaks. So I'm happy to revert to not delaying
anything. This makes tests pass again.
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Thu, 06 Apr 2023 14:17:50 +0100 |
parent | 12977:74b9e05af71e |
child | 13029:8ad432953300 |
rev | line source |
---|---|
12968
efdb7f2cd578
mod_debug_reset: New module to "reset" a running server (e.g. for testing)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1 -- This module will "reset" the server when the client connection count drops |
efdb7f2cd578
mod_debug_reset: New module to "reset" a running server (e.g. for testing)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2 -- to zero. This is somewhere between a reload and a full process restart. |
efdb7f2cd578
mod_debug_reset: New module to "reset" a running server (e.g. for testing)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3 -- It is useful to ensure isolation between test runs, for example. It may |
efdb7f2cd578
mod_debug_reset: New module to "reset" a running server (e.g. for testing)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
4 -- also be of use for some kinds of manual testing. |
efdb7f2cd578
mod_debug_reset: New module to "reset" a running server (e.g. for testing)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
5 |
efdb7f2cd578
mod_debug_reset: New module to "reset" a running server (e.g. for testing)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
6 module:set_global(); |
efdb7f2cd578
mod_debug_reset: New module to "reset" a running server (e.g. for testing)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
7 |
12977
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12970
diff
changeset
|
8 local hostmanager = require "prosody.core.hostmanager"; |
12968
efdb7f2cd578
mod_debug_reset: New module to "reset" a running server (e.g. for testing)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
9 |
12977
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12970
diff
changeset
|
10 local timer = require "prosody.util.timer"; |
12968
efdb7f2cd578
mod_debug_reset: New module to "reset" a running server (e.g. for testing)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
11 |
efdb7f2cd578
mod_debug_reset: New module to "reset" a running server (e.g. for testing)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
12 local function do_reset() |
efdb7f2cd578
mod_debug_reset: New module to "reset" a running server (e.g. for testing)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
13 module:log("info", "Performing reset..."); |
efdb7f2cd578
mod_debug_reset: New module to "reset" a running server (e.g. for testing)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
14 local hosts = {}; |
efdb7f2cd578
mod_debug_reset: New module to "reset" a running server (e.g. for testing)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
15 for host in pairs(prosody.hosts) do |
efdb7f2cd578
mod_debug_reset: New module to "reset" a running server (e.g. for testing)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
16 table.insert(hosts, host); |
efdb7f2cd578
mod_debug_reset: New module to "reset" a running server (e.g. for testing)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
17 end |
efdb7f2cd578
mod_debug_reset: New module to "reset" a running server (e.g. for testing)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
18 module:fire_event("server-resetting"); |
efdb7f2cd578
mod_debug_reset: New module to "reset" a running server (e.g. for testing)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 for _, host in ipairs(hosts) do |
efdb7f2cd578
mod_debug_reset: New module to "reset" a running server (e.g. for testing)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 hostmanager.deactivate(host); |
13028
b2e6a175537d
mod_debug_reset: Don't delay operations until next tick
Matthew Wild <mwild1@gmail.com>
parents:
12977
diff
changeset
|
21 hostmanager.activate(host); |
b2e6a175537d
mod_debug_reset: Don't delay operations until next tick
Matthew Wild <mwild1@gmail.com>
parents:
12977
diff
changeset
|
22 module:log("info", "Reset complete"); |
b2e6a175537d
mod_debug_reset: Don't delay operations until next tick
Matthew Wild <mwild1@gmail.com>
parents:
12977
diff
changeset
|
23 module:fire_event("server-reset"); |
12968
efdb7f2cd578
mod_debug_reset: New module to "reset" a running server (e.g. for testing)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
24 end |
efdb7f2cd578
mod_debug_reset: New module to "reset" a running server (e.g. for testing)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
25 end |
efdb7f2cd578
mod_debug_reset: New module to "reset" a running server (e.g. for testing)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
26 |
efdb7f2cd578
mod_debug_reset: New module to "reset" a running server (e.g. for testing)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
27 function module.add_host(host_module) |
efdb7f2cd578
mod_debug_reset: New module to "reset" a running server (e.g. for testing)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
28 host_module:hook("resource-unbind", function () |
efdb7f2cd578
mod_debug_reset: New module to "reset" a running server (e.g. for testing)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
29 if next(prosody.full_sessions) == nil then |
13028
b2e6a175537d
mod_debug_reset: Don't delay operations until next tick
Matthew Wild <mwild1@gmail.com>
parents:
12977
diff
changeset
|
30 do_reset(); |
12968
efdb7f2cd578
mod_debug_reset: New module to "reset" a running server (e.g. for testing)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
31 end |
efdb7f2cd578
mod_debug_reset: New module to "reset" a running server (e.g. for testing)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
32 end); |
efdb7f2cd578
mod_debug_reset: New module to "reset" a running server (e.g. for testing)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
33 end |
efdb7f2cd578
mod_debug_reset: New module to "reset" a running server (e.g. for testing)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
34 |
efdb7f2cd578
mod_debug_reset: New module to "reset" a running server (e.g. for testing)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
35 local console_env = module:shared("/*/admin_shell/env"); |
efdb7f2cd578
mod_debug_reset: New module to "reset" a running server (e.g. for testing)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
36 console_env.debug_reset = { |
efdb7f2cd578
mod_debug_reset: New module to "reset" a running server (e.g. for testing)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
37 reset = do_reset; |
efdb7f2cd578
mod_debug_reset: New module to "reset" a running server (e.g. for testing)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
38 }; |