You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ponymail.apache.org by se...@apache.org on 2022/01/26 00:26:48 UTC

[incubator-ponymail-foal] branch master updated: Allow test to stop the server

This is an automated email from the ASF dual-hosted git repository.

sebb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-ponymail-foal.git


The following commit(s) were added to refs/heads/master by this push:
     new 8648be7  Allow test to stop the server
8648be7 is described below

commit 8648be7ccdaf989c4e52520f803b1ac1c8c8c862
Author: Sebb <se...@apache.org>
AuthorDate: Wed Jan 26 00:26:39 2022 +0000

    Allow test to stop the server
---
 server/main.py | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/server/main.py b/server/main.py
index 13a1b48..c2a2992 100644
--- a/server/main.py
+++ b/server/main.py
@@ -68,6 +68,7 @@ class Server(plugins.server.BaseServer):
         self.api_logger = None
         self.foal_version = PONYMAIL_FOAL_VERSION
         self.server_version = PONYMAIL_SERVER_VERSION
+        self.stoppable = False # allow remote stop for tests
 
         # Make a pool of database connections for async queries
         pool_size = self.config.database.pool_size
@@ -103,6 +104,7 @@ class Server(plugins.server.BaseServer):
             self.api_logger = logging.getLogger('ponymail.apilog')
             self.api_logger.setLevel(args.apilog)
             self.api_logger.addHandler(logging.StreamHandler())
+        self.stoppable = args.stoppable
             
 
     async def handle_request(
@@ -123,6 +125,8 @@ class Server(plugins.server.BaseServer):
         body_type = "form"
         # Support URLs of form /api/handler/extra?query
         handler = request.path.split("/")[2]
+        if self.stoppable and handler == 'stop':
+            raise KeyboardInterrupt # TODO find tidier solution ...
         if handler.endswith(".lua"):
             body_type = "form"
             handler = handler[:-4]
@@ -239,5 +243,10 @@ if __name__ == "__main__":
         "--apilog",
         help="api log level (e.g. INFO or DEBUG)",
     )
+    parser.add_argument(
+        "--stoppable",
+        action='store_true',
+        help="Allow remote stop for testing",
+    )
     cliargs = parser.parse_args()
     Server(cliargs).run()