cheroot.test.test_server module¶
Tests for the HTTP server.
- class cheroot.test.test_server._OwnStatsServer(bind_addr, gateway, minthreads=10, maxthreads=-1, server_name=None, peercreds_enabled=False, peercreds_resolve_enabled=False, reuse_port=False)¶
Bases:
HTTPServerA server that replaces clear_stats() without calling the parent’s.
- class cheroot.test.test_server._TestGateway(req)¶
Bases:
Gateway- respond()¶
Process the current request. Must be overridden in a subclass.
- send_payload(payload)¶
- cheroot.test.test_server._garbage_bin()¶
Disable garbage collection when this fixture is in use.
- cheroot.test.test_server._make_server(server_class: type[HTTPServer] = <class 'cheroot.server.HTTPServer'>, **kwargs: Any) HTTPServer¶
Make a server on an ephemeral port, without starting it.
- cheroot.test.test_server._make_wsgi_server(app: Callable[[...], Any]) Server¶
Make a WSGI server with one worker on an ephemeral port.
- cheroot.test.test_server._retire_workers(httpserver: HTTPServer) None¶
Retire every worker but one, and wait until they have exited.
- cheroot.test.test_server._serve_requests(server: Server, count: int) None¶
Run a server on a new ephemeral port and send it some requests.
- cheroot.test.test_server._start_server_with_workers(request: FixtureRequest, server_class: type[HTTPServer] = <class 'cheroot.server.HTTPServer'>) HTTPServer¶
Start a server with one worker that stays and some that can retire.
- cheroot.test.test_server._wait_until(*, compute_condition: Callable[[], bool], timeout: float = 10) bool¶
Wait until the condition is true or the timeout expires.
- cheroot.test.test_server.many_open_sockets(request, resource_limit)¶
Allocate a lot of file descriptors by opening dummy sockets.
- cheroot.test.test_server.peercreds_enabled_server(http_server, unix_sock_file)¶
Construct a test server with
peercreds_enabled.
- cheroot.test.test_server.resource_limit(request)¶
Set the resource limit two times bigger then requested.
- cheroot.test.test_server.test_bind_addr_inet(http_server, ip_addr)¶
Check that bound IP address is stored in server.
- cheroot.test.test_server.test_bind_addr_unix(http_server, unix_sock_file)¶
Check that bound UNIX socket address is stored in server.
- cheroot.test.test_server.test_bind_addr_unix_abstract(http_server, unix_abstract_sock)¶
Check that bound UNIX abstract socket address is stored in server.
- cheroot.test.test_server.test_high_number_of_file_descriptors(native_server_client, resource_limit)¶
Test the server does not crash with a high file-descriptor value.
This test shouldn’t cause a server crash when trying to access file-descriptor higher than 1024.
The earlier implementation used to rely on
select()syscall that doesn’t support file descriptors with numbers higher than 1024.
- cheroot.test.test_server.test_overload_results_in_suitable_http_error(request)¶
A server that can’t keep up with requests returns a 503 HTTP error.
- cheroot.test.test_server.test_overload_thread_does_not_leak()¶
On shutdown the overload thread exits.
This is a test for issue #769.
- cheroot.test.test_server.test_peercreds_unix_sock(http_request_timeout, peercreds_enabled_server)¶
Check that
PEERCREDlookup works when enabled.
- cheroot.test.test_server.test_peercreds_unix_sock_with_lookup(http_request_timeout, peercreds_enabled_server)¶
Check that
PEERCREDresolution works when enabled.
- cheroot.test.test_server.test_prepare_makes_server_ready()¶
Check that prepare() makes the server ready, and stop() clears it.
- cheroot.test.test_server.test_retired_threads_preserve_totals(request: FixtureRequest, statistics: str) None¶
Test that retired workers drop their records but keep totals.
- cheroot.test.test_server.test_retiring_worker_removes_its_changed_record(request: FixtureRequest, change: str) None¶
Test that a worker removes its record even after changes to it.
- cheroot.test.test_server.test_reuse_port(http_server, ip_addr, mocker)¶
Check that port initialized externally can be reused.
- cheroot.test.test_server.test_server_interrupt(exc_cls)¶
Check that assigning interrupt stops the server.
- cheroot.test.test_server.test_server_throughput_comes_from_worker_counts(request: FixtureRequest, direction: str, replacement: object) None¶
Test that server throughput sums each worker’s bytes per work time.
- cheroot.test.test_server.test_server_with_own_clear_stats_keeps_worker_records(request: FixtureRequest) None¶
Test that workers keep using a server’s own records mapping.
- cheroot.test.test_server.test_serving_is_false_and_stop_returns_after_ctrlc()¶
Check that stop() interrupts running of serve().
- cheroot.test.test_server.test_statistics_are_not_published_after_failed_bind(monkeypatch: MonkeyPatch) None¶
Test that a server that fails to bind publishes no statistics.
- cheroot.test.test_server.test_statistics_are_published_while_serving(request: FixtureRequest) None¶
Test that a server’s statistics are published only while it serves.
- cheroot.test.test_server.test_statistics_cleared_between_runs_keep_their_counts() None¶
Test that statistics replaced between runs keep their own counts.
- cheroot.test.test_server.test_statistics_survive_http_worker_churn() None¶
Test that server statistics retain totals after workers retire.
- cheroot.test.test_server.test_stop_interrupts_serve()¶
Check that stop() interrupts running of serve().
- cheroot.test.test_server.test_threadpool_invalid_threadrange(minthreads, maxthreads, error)¶
Test that a ThreadPool rejects invalid min/max values.
The ThreadPool should raise an error with the proper message when initialized with an invalid min+max number of threads.
- cheroot.test.test_server.test_threadpool_multistart_validation(monkeypatch)¶
Test for ThreadPool multi-start behavior.
Tests that when calling start() on a ThreadPool multiple times raises a
RuntimeError
- cheroot.test.test_server.test_threadpool_threadrange_set(minthreads, maxthreads, inited_maxthreads)¶
Test setting the number of threads in a ThreadPool.
The ThreadPool should properly set the min+max number of the threads to use in the pool if those limits are valid.
- cheroot.test.test_server.test_worker_retiring_after_clear_stats_keeps_to_its_statistics(request: FixtureRequest) None¶
Test that a worker’s counts go to the statistics that it joined.
- cheroot.test.test_server.unix_abstract_sock()¶
Return an abstract UNIX socket address.
- cheroot.test.test_server.unix_file_sock()¶
Yield a UNIX file socket.
- cheroot.test.test_server.unix_sock_file(request)¶
Check that bound UNIX socket address is stored in server.