]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Test] Add diagnostic logging to dummy_http.py
authorVsevolod Stakhov <vsevolod@rspamd.com>
Sat, 6 Dec 2025 09:37:32 +0000 (09:37 +0000)
committerVsevolod Stakhov <vsevolod@rspamd.com>
Sat, 6 Dec 2025 09:37:32 +0000 (09:37 +0000)
- Add startup progress messages to stderr
- Capture exceptions with full traceback
- Write PID only after successful server start
- Log output on failure in robot tests

test/functional/lib/rspamd.robot
test/functional/util/dummy_http.py

index eb69fed4efb8e24bcbdfaad70d18ca9a5a04753c..d59f158f23fcf951a2b8c0274825497cf7136c10 100644 (file)
@@ -495,14 +495,34 @@ Sync Fuzzy Storage
 
 Run Dummy Http
   ${result} =  Start Process  ${RSPAMD_TESTDIR}/util/dummy_http.py  -pf  /tmp/dummy_http.pid
-  Wait Until Created  /tmp/dummy_http.pid  timeout=2 second
+  ...  stderr=/tmp/dummy_http.log  stdout=/tmp/dummy_http.log
+  ${status}  ${error} =  Run Keyword And Ignore Error  Wait Until Created  /tmp/dummy_http.pid  timeout=2 second
+  IF  '${status}' == 'FAIL'
+    ${logstatus}  ${log} =  Run Keyword And Ignore Error  Get File  /tmp/dummy_http.log
+    IF  '${logstatus}' == 'PASS'
+      Log  dummy_http.py failed to start. Log output:\n${log}  level=ERROR
+    ELSE
+      Log  dummy_http.py failed to start. No log file found at /tmp/dummy_http.log  level=ERROR
+    END
+    Fail  dummy_http.py did not create PID file in 2 seconds
+  END
   Export Scoped Variables  ${RSPAMD_SCOPE}  DUMMY_HTTP_PROC=${result}
 
 Run Dummy Https
   ${result} =  Start Process  ${RSPAMD_TESTDIR}/util/dummy_http.py
   ...  -c  ${RSPAMD_TESTDIR}/util/server.pem  -k  ${RSPAMD_TESTDIR}/util/server.pem
   ...  -pf  /tmp/dummy_https.pid  -p  18081
-  Wait Until Created  /tmp/dummy_https.pid  timeout=2 second
+  ...  stderr=/tmp/dummy_https.log  stdout=/tmp/dummy_https.log
+  ${status}  ${error} =  Run Keyword And Ignore Error  Wait Until Created  /tmp/dummy_https.pid  timeout=2 second
+  IF  '${status}' == 'FAIL'
+    ${logstatus}  ${log} =  Run Keyword And Ignore Error  Get File  /tmp/dummy_https.log
+    IF  '${logstatus}' == 'PASS'
+      Log  dummy_https.py failed to start. Log output:\n${log}  level=ERROR
+    ELSE
+      Log  dummy_https.py failed to start. No log file found at /tmp/dummy_https.log  level=ERROR
+    END
+    Fail  dummy_https.py did not create PID file in 2 seconds
+  END
   Export Scoped Variables  ${RSPAMD_SCOPE}  DUMMY_HTTPS_PROC=${result}
 
 Run Dummy Llm
index 832dbdc7975f414af369cc9ab15ce661bcaa06d1..c1f573390a1837719869196fb0c64ecdf66b98a8 100755 (executable)
@@ -8,6 +8,8 @@ import tornado.httpserver
 import ssl
 import argparse
 import os
+import sys
+import traceback
 
 class MainHandler(tornado.web.RequestHandler):
     @tornado.gen.coroutine
@@ -118,27 +120,39 @@ async def main():
     parser.add_argument("--pidfile", "-pf", help="path to the PID file")
     args = parser.parse_args()
 
+    print(f"dummy_http.py: Starting server on {args.bind}:{args.port}", file=sys.stderr)
+
     # Create the Tornado application
     app = make_app()
 
     # If keyfile and certfile are provided, create an HTTPS server.
     # Otherwise, create an HTTP server.
     if args.keyfile and args.certfile:
+        print(f"dummy_http.py: Using SSL with cert={args.certfile}, key={args.keyfile}", file=sys.stderr)
         ssl_ctx = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH)
         ssl_ctx.load_cert_chain(args.certfile, args.keyfile)
         server = tornado.httpserver.HTTPServer(app, ssl_options=ssl_ctx)
     else:
         server = tornado.httpserver.HTTPServer(app)
 
+    # Start the server
+    server.bind(args.port, args.bind)
+    server.start(1)
+
     # Write the PID to the specified PID file, if provided
+    # Do this AFTER successful bind/start so we know the server is actually running
     if args.pidfile:
         dummy_killer.write_pid(args.pidfile)
+        print(f"dummy_http.py: PID file written to {args.pidfile}", file=sys.stderr)
 
-    # Start the server
-    server.bind(args.port, args.bind)
-    server.start(1)
+    print(f"dummy_http.py: Server started successfully, listening on {args.bind}:{args.port}", file=sys.stderr)
 
     await asyncio.Event().wait()
 
 if __name__ == "__main__":
-    asyncio.run(main())
+    try:
+        asyncio.run(main())
+    except Exception as e:
+        print(f"dummy_http.py: FATAL ERROR: {type(e).__name__}: {e}", file=sys.stderr)
+        traceback.print_exc(file=sys.stderr)
+        sys.exit(1)