cheroot.test.test_makefile module

Tests for cheroot.makefile.

class cheroot.test.test_makefile.DeadSocket(exc=None)

Bases: MockSocket

A mock socket whose file descriptor is already invalid.

Simulates a connection that was torn down (e.g. an aborted TLS session) so that any attempt to send raises OSError.

send(val)

Fail as if the underlying descriptor is gone.

class cheroot.test.test_makefile.MockSocket

Bases: object

A mock socket.

_decref_socketios()

Emulate socket I/O reference decrement.

recv(size)

Simulate recv for Python 2.

recv_into(buf)

Simulate recv_into for Python 3.

send(val)

Simulate a send.

cheroot.test.test_makefile.test_bytes_read()

Reader should capture bytes read.

cheroot.test.test_makefile.test_bytes_written()

Writer should capture bytes written.

cheroot.test.test_makefile.test_close_on_dead_socket_is_swallowed()

Closing a writer with a dead socket must not raise.

close performs an implicit flush; on a dead descriptor this is the exact path exercised by the finalizer IOBase.__del__.

cheroot.test.test_makefile.test_flush_on_dead_socket_is_swallowed(exc)

Flushing to a dead socket must not raise.

A buffered write flushed after the socket’s descriptor became invalid should not propagate the error, otherwise it taints the worker thread teardown path and can wedge the server over time.

Ref: https://github.com/cherrypy/cheroot/issues/710