cheroot.test.test_server module¶
Tests for the HTTP server.
- class cheroot.test.test_server._HeldConnection¶
Bases:
objectA connection that its worker handles until it is closed.
- class cheroot.test.test_server._LockInterruptedOnAcquire(pool: ThreadPool, thread: Thread)¶
Bases:
objectThe pool’s lock, interrupted once before one thread acquires it.
- class cheroot.test.test_server._LockInterruptedOnRelease(pool: ThreadPool)¶
Bases:
objectThe pool’s lock, interrupted once as it is released.
- class cheroot.test.test_server._ObservedLock(pool: ThreadPool, waiting: Event)¶
Bases:
objectReport a caller that has to wait for the pool’s lock.
- class cheroot.test.test_server._ObservedStopLock(pool: ThreadPool, waiting: Event)¶
Bases:
objectReport a stop() call that has to wait for the one under way.
- class cheroot.test.test_server._StoppingConnection(pool: ThreadPool, together: Barrier | None = None, stop_kwargs: dict[str, float | None] | None = None)¶
Bases:
_HeldConnectionA connection whose handler stops the pool, then waits to be closed.
- 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._assert_empty_pool_queue(pool: ThreadPool) None¶
Check that no connection or retirement request remains queued.
- cheroot.test.test_server._assert_restart_ignores_leftovers(pool: ThreadPool) None¶
Check that a request left by a stop does not end a restarted thread.
- cheroot.test.test_server._bounded_pool_put(pool: ThreadPool, monkeypatch: MonkeyPatch) Iterator[None]¶
Bound the old enqueue deadlock so regressions fail without hanging.
- cheroot.test.test_server._count_live_threads(pool: ThreadPool) int¶
Count the pool’s threads that have not exited yet.
- cheroot.test.test_server._garbage_bin()¶
Disable garbage collection when this fixture is in use.
- cheroot.test.test_server._hold_retiring_workers(monkeypatch: MonkeyPatch) Iterator[Queue[WorkerThread]]¶
Hold workers after their processing loop has consumed a retirement.
- cheroot.test.test_server._interrupt_a_shrink_while_another_is_due(pool: ThreadPool, monkeypatch: MonkeyPatch) None¶
Interrupt a call once another has reserved a shutdown.
- cheroot.test.test_server._interrupt_after(put: Callable[[object], None]) Callable[[object], None]¶
Wrap a put() so that an interrupt follows the request it queues.
- cheroot.test.test_server._join_thread(thread: Thread) None¶
Join a started test thread and fail if it does not finish.
- cheroot.test.test_server._make_server(server_class: type[HTTPServer] = <class 'cheroot.server.HTTPServer'>, *, minthreads: int = 10) HTTPServer¶
Make a server on an ephemeral port, without starting it.
- cheroot.test.test_server._make_wsgi_server(app: Callable[[...], object]) Server¶
Make a WSGI server with one worker on an ephemeral port.
- cheroot.test.test_server._paused_workers(monkeypatch: MonkeyPatch) Iterator[Event]¶
Hold workers before they consume requests, and always release them.
- cheroot.test.test_server._pool_of_daemon_threads(request: FixtureRequest, *, minthreads: int) ThreadPool¶
Start a pool whose threads do not keep the tests from ending.
Threads inherit their daemon flag, so starting the pool from a daemon thread makes a regression that leaves threads waiting fail the test instead of hanging the run.
- cheroot.test.test_server._pool_with_one_slot(request: FixtureRequest, *, minthreads: int) ThreadPool¶
Start a pool whose queue holds one item.
- cheroot.test.test_server._prepared_pool(request: FixtureRequest, *, minthreads: int) ThreadPool¶
Prepare a server with a set number of threads, and return its pool.
- cheroot.test.test_server._read_idle_while_retiring(pool: ThreadPool) list[int]¶
Return the idle counts that differ from 1 while threads retire.
- cheroot.test.test_server._release_events(*events: Event) None¶
Unblock test workers during cleanup, including assertion failures.
- cheroot.test.test_server._run_overlapping_shrinks(first: Thread, second: Thread, first_enqueue: Event, second_progress: Event, release_enqueue: Event) None¶
Hold the first enqueue until the second call has made its decision.
- cheroot.test.test_server._shrink_and_notify(pool: ThreadPool, finished: Event, errors: list[BaseException]) None¶
Capture a shrink failure and signal that the caller has finished.
- cheroot.test.test_server._stop_during_growth(pool: ThreadPool, monkeypatch: MonkeyPatch) None¶
Overlap growth and stop without using timing to order the calls.
- cheroot.test.test_server._stop_during_shrink_enqueue(pool: ThreadPool, monkeypatch: MonkeyPatch) None¶
Stop the pool while a shrink caller has yet to insert its request.
- cheroot.test.test_server._stop_in_daemon(pool: ThreadPool) Thread¶
Stop a pool in a thread that does not keep the tests from ending.
- cheroot.test.test_server._wait_for_empty_queue(pool: ThreadPool) bool¶
Wait for the workers to take every request in the queue.
- cheroot.test.test_server._wait_for_thread_count(pool: ThreadPool, count: int) bool¶
Wait for the pool to have the expected number of live workers.
- 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.single_thread_pool(request: FixtureRequest) ThreadPool¶
Return the pool of a prepared server with a minimum of one thread.
- 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_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_serving_is_false_and_stop_returns_after_ctrlc()¶
Check that stop() interrupts running of serve().
- cheroot.test.test_server.test_stop_interrupts_serve()¶
Check that stop() interrupts running of serve().
- cheroot.test.test_server.test_threadpool_concurrent_shrink_keeps_minimum(single_thread_pool: ThreadPool, monkeypatch: MonkeyPatch, queue_size: int) None¶
Concurrent calls must not spend the same retirement budget twice.
- cheroot.test.test_server.test_threadpool_grow_is_refused_until_stop_returns(request: FixtureRequest, monkeypatch: MonkeyPatch) None¶
A thread grown while stop() waits for old ones would outlive it.
- cheroot.test.test_server.test_threadpool_grow_while_stopping_is_refused(single_thread_pool: ThreadPool, monkeypatch: MonkeyPatch) None¶
A thread grown during stop() could take a busy thread’s request.
- cheroot.test.test_server.test_threadpool_idle_is_accurate_while_threads_retire(single_thread_pool: ThreadPool) None¶
pool.idle is accurate throughout concurrent retirements.
- cheroot.test.test_server.test_threadpool_interrupt_after_enqueue_keeps_minimum(request: FixtureRequest, monkeypatch: MonkeyPatch, *, worker_claimed: bool) None¶
Retrying after an interrupted successful enqueue must keep the minimum.
- cheroot.test.test_server.test_threadpool_interrupted_shrink_keeps_other_calls_shutdowns(single_thread_pool: ThreadPool, monkeypatch: MonkeyPatch) None¶
An interrupted call gives back only shutdowns of its own requests.
- cheroot.test.test_server.test_threadpool_interrupted_shrink_releases_unused_reservations(request: FixtureRequest, monkeypatch: MonkeyPatch, queued_before_error: int) None¶
An interrupted shrink keeps only successfully queued retirements.
- cheroot.test.test_server.test_threadpool_interrupted_stop_lets_running_threads_exit(monkeypatch: MonkeyPatch) None¶
Test that a thread still running after an interrupted stop() exits.
- 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_outside_stop_during_a_worker_stop(request: FixtureRequest, monkeypatch: MonkeyPatch) None¶
A stop() that comes during a worker’s waits for it, then for all.
- cheroot.test.test_server.test_threadpool_overlapping_stops_end_every_thread(request: FixtureRequest, monkeypatch: MonkeyPatch) None¶
A stop() that comes as another queues on a small queue, both finish.
- cheroot.test.test_server.test_threadpool_reap_before_enqueue_returns_keeps_idle_count(request: FixtureRequest, monkeypatch: MonkeyPatch) None¶
Reaping before the enqueue returns must not leave a phantom shutdown.
- cheroot.test.test_server.test_threadpool_restart_waits_for_a_worker_that_stopped_it(request: FixtureRequest) None¶
A pool that its worker stopped starts again once that worker exits.
- cheroot.test.test_server.test_threadpool_restarts_after_late_shrink_enqueue(monkeypatch: MonkeyPatch) None¶
A retirement request arriving after stop must not retire a new worker.
- cheroot.test.test_server.test_threadpool_restarts_after_stop(request: FixtureRequest, shrinking: str) None¶
Test that a pool stopped after or during shrinking restarts.
- cheroot.test.test_server.test_threadpool_shrink_calls_are_additive(single_thread_pool: ThreadPool) None¶
Test two close-together shrink() calls retire the total requested.
- cheroot.test.test_server.test_threadpool_shrink_interrupted_after_a_stop(single_thread_pool: ThreadPool, monkeypatch: MonkeyPatch) None¶
A shrink() interrupted after a stop() leaves the next run’s count.
- cheroot.test.test_server.test_threadpool_shrink_interrupted_after_its_reservation(single_thread_pool: ThreadPool, monkeypatch: MonkeyPatch) None¶
A shrink() interrupted before it queues gives its shutdown back.
- cheroot.test.test_server.test_threadpool_shrink_keeps_minimum(request: FixtureRequest) None¶
Test that shrink() keeps the minimum number of threads.
A retirement due when another thread exits must keep the minimum.
- cheroot.test.test_server.test_threadpool_shrink_skips_threads_shutting_down(request: FixtureRequest, monkeypatch: MonkeyPatch) None¶
A thread that is shutting down is neither idle nor asked again.
- cheroot.test.test_server.test_threadpool_start_is_refused_until_stop_returns(single_thread_pool: ThreadPool, monkeypatch: MonkeyPatch) None¶
A pool started again before stop() returns would outlive it.
- cheroot.test.test_server.test_threadpool_stop_drops_requests_already_consumed(request: FixtureRequest, monkeypatch: MonkeyPatch) None¶
An interrupted join must not retain requests for retiring workers.
- cheroot.test.test_server.test_threadpool_stop_ends_threads_whatever_is_pending(request: FixtureRequest) None¶
Test that stop() ends every thread even if a request went missing.
- cheroot.test.test_server.test_threadpool_stop_includes_growing_workers(single_thread_pool: ThreadPool, monkeypatch: MonkeyPatch) None¶
A stop overlapping growth must leave no worker behind.
- cheroot.test.test_server.test_threadpool_stop_interrupted_in_its_cleanup_can_be_repeated(request: FixtureRequest, monkeypatch: MonkeyPatch) None¶
A stop() interrupted as it tidies up lets the pool stop and start.
- cheroot.test.test_server.test_threadpool_stop_interrupted_while_waiting_can_be_repeated(request: FixtureRequest, monkeypatch: MonkeyPatch) None¶
A stop() interrupted as it waits leaves the next call to end the pool.
- cheroot.test.test_server.test_threadpool_stop_preserves_queued_connections(monkeypatch: MonkeyPatch) None¶
Stop queues no request for a thread that does not run.
- cheroot.test.test_server.test_threadpool_stop_retries_an_interrupted_enqueue(request: FixtureRequest, monkeypatch: MonkeyPatch) None¶
A second stop can complete an interrupted batch of stop requests.
- cheroot.test.test_server.test_threadpool_stop_with_a_bounded_queue(request: FixtureRequest, monkeypatch: MonkeyPatch) None¶
Stop must finish even when dead workers outnumber queue slots.
- cheroot.test.test_server.test_threadpool_stopped_by_its_own_worker() None¶
Test that a worker that stops its own pool still exits.
- cheroot.test.test_server.test_threadpool_stopped_on_interrupt_by_its_own_worker() None¶
Test that a worker that interrupts its server leaves no request.
- 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_threadpool_unneeded_shrink_request_keeps_threads(request: FixtureRequest, monkeypatch: MonkeyPatch) None¶
A retirement request that its call canceled must not end a thread.
An unrelated worker exit must not consume a queued retirement.
- cheroot.test.test_server.test_threadpool_worker_stop_during_an_outside_stop(request: FixtureRequest) None¶
A worker’s stop() returns at once while another call ends the threads.
- cheroot.test.test_server.test_threadpool_worker_stop_without_a_timeout_does_not_wait(request: FixtureRequest) None¶
A worker’s stop() without a timeout only asks the threads to stop.
- cheroot.test.test_server.test_threadpool_worker_that_stops_its_pool_closes_stuck_connections(request: FixtureRequest) None¶
A worker that stops its pool still closes a stuck thread’s connection.
- cheroot.test.test_server.test_threadpool_workers_do_not_check_other_threads(single_thread_pool: ThreadPool, monkeypatch: MonkeyPatch) None¶
A worker that takes a retirement request does not call is_alive().
- cheroot.test.test_server.test_threadpool_workers_that_stop_their_pool_at_once(request: FixtureRequest, n_workers: int, stop_kwargs: dict[str, float | None]) None¶
Workers that stop their pool at once do not wait for each other.
- 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.