test_routes_server_threading
Tests for the threaded routes server request path.
Requests are served on threads that are never STA while pyRevit directs stderr to its script output console, a WPF window that can only be created on Revit's STA UI thread. An exception escaping a serving thread is printed there and terminates the Revit process.
ThreadedHttpServer.process_request_thread must therefore contain every
failure on the request path, including the per-request cleanup that runs on
an already closed socket after the server has been stopped.
Access logging runs on those same threads, so HttpRequestHandler must
report every request through mlogger and never reach stderr either.
Classes
ProcessRequestThreadTests
Bases: _LoggerPatchedTestCase
Tests for ThreadedHttpServer.process_request_thread.
Methods:
test_serves_request_and_runs_cleanup()
A successful request is served and its socket cleaned up.
Source code in pyrevitlib/pyrevit/unittests/test_routes_server_threading.py
test_cleanup_failure_on_closed_socket_does_not_escape()
Cleanup raising on a closed socket must not escape the thread.
Source code in pyrevitlib/pyrevit/unittests/test_routes_server_threading.py
test_cleanup_failure_of_any_type_does_not_escape()
Cleanup failures are contained whatever exception type is raised.
Source code in pyrevitlib/pyrevit/unittests/test_routes_server_threading.py
test_cleanup_failure_is_not_reported_as_a_request_error()
A served request is not reported as failed when cleanup raises.
Source code in pyrevitlib/pyrevit/unittests/test_routes_server_threading.py
test_inherited_cleanup_runs_against_a_closed_socket()
The inherited cleanup path is safe on a genuinely closed socket.
Source code in pyrevitlib/pyrevit/unittests/test_routes_server_threading.py
test_request_failure_is_reported()
A request that raises is routed to handle_error.
Source code in pyrevitlib/pyrevit/unittests/test_routes_server_threading.py
test_request_failure_still_runs_cleanup()
Cleanup runs even when serving the request raised.
Source code in pyrevitlib/pyrevit/unittests/test_routes_server_threading.py
test_request_and_cleanup_failures_are_both_contained()
Nothing escapes when both the request and its cleanup raise.
Source code in pyrevitlib/pyrevit/unittests/test_routes_server_threading.py
test_error_reporting_failure_does_not_escape()
A failure inside handle_error must not escape either.
Source code in pyrevitlib/pyrevit/unittests/test_routes_server_threading.py
test_nothing_is_written_to_stderr()
Serving and cleanup failures must never reach stderr.
Source code in pyrevitlib/pyrevit/unittests/test_routes_server_threading.py
test_no_exception_escapes_the_serving_thread()
Run on a thread as the server does; nothing may escape it.
Source code in pyrevitlib/pyrevit/unittests/test_routes_server_threading.py
setUp()
HandleErrorTests
Bases: _LoggerPatchedTestCase
Tests for ThreadedHttpServer.handle_error.
Methods:
test_reports_through_the_logger()
Request errors are recorded through mlogger, not printed.
Source code in pyrevitlib/pyrevit/unittests/test_routes_server_threading.py
test_does_not_write_to_stderr()
handle_error must not reach the script output console.
Source code in pyrevitlib/pyrevit/unittests/test_routes_server_threading.py
setUp()
LogMessageTests
Bases: _LoggerPatchedTestCase
Tests for HttpRequestHandler.log_message.
Methods:
test_records_the_message_through_the_logger()
Request logging is recorded through mlogger, not printed.
Source code in pyrevitlib/pyrevit/unittests/test_routes_server_threading.py
test_does_not_write_to_stderr()
log_message must not reach the script output console.
Source code in pyrevitlib/pyrevit/unittests/test_routes_server_threading.py
test_served_and_rejected_requests_both_stay_off_stderr()
Every inherited logging entry point goes through the override.