mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-23 00:46:16 -04:00
Refactor startup/shutdown for tests
* `src/node/server.js` can now be run as a script (for normal operation) or imported as a module (for tests). * Move shutdown actions to `src/node/server.js` to be close to the startup actions. * Put startup and shutdown in functions so that tests can call them. * Use `await` instead of callbacks. * Block until the HTTP server is listening to avoid races during test startup. * Add a new `shutdown` hook. * Use the `shutdown` hook to: * close the HTTP server * call `end()` on the stats collection to cancel its timers * call `terminate()` on the Threads.Pool to stop the workers * Exit with exit code 0 (instead of 1) on SIGTERM. * Export the HTTP server so that tests can get the HTTP server's port via `server.address().port` when `settings.port` is 0.
This commit is contained in:
parent
a4be577ed1
commit
a000a93dc6
11 changed files with 171 additions and 151 deletions
|
@ -10,6 +10,28 @@ Things in context:
|
|||
|
||||
Use this hook to receive the global settings in your plugin.
|
||||
|
||||
## shutdown
|
||||
Called from: src/node/server.js
|
||||
|
||||
Things in context: None
|
||||
|
||||
This hook runs before shutdown. Use it to stop timers, close sockets and files,
|
||||
flush buffers, etc. The database is not available while this hook is running.
|
||||
The shutdown function must not block for long because there is a short timeout
|
||||
before the process is forcibly terminated.
|
||||
|
||||
The shutdown function must return a Promise, which must resolve to `undefined`.
|
||||
Returning `callback(value)` will return a Promise that is resolved to `value`.
|
||||
|
||||
Example:
|
||||
|
||||
```
|
||||
// using an async function
|
||||
exports.shutdown = async (hookName, context) => {
|
||||
await flushBuffers();
|
||||
};
|
||||
```
|
||||
|
||||
## pluginUninstall
|
||||
Called from: src/static/js/pluginfw/installer.js
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue