userver: pytest_userver.chaos.TcpGate Class Reference
Loading...
Searching...
No Matches
pytest_userver.chaos.TcpGate Class Reference

Detailed Description

Implements TCP chaos-proxy logic such as accepting incoming tcp client connections.

On each new connection new tcp client connects to server (host_to_server, port_to_server).

See also
Chaos Testing

Definition at line 753 of file chaos.py.

+ Inheritance diagram for pytest_userver.chaos.TcpGate:
+ Collaboration diagram for pytest_userver.chaos.TcpGate:

Public Member Functions

None __init__ (self, GateRoute route, EvLoop loop)
 
int connections_count (self)
 Returns maximal amount of connections going through the gate at the moment.
 
None wait_for_connections (self, *count=1, timeout=0.0)
 Wait for at least count connections going through the gate.
 
- Public Member Functions inherited from pytest_userver.chaos.BaseGate
'BaseGate__aenter__ (self)
 
None __aexit__ (self, exc_type, exc_value, traceback)
 
 start (self)
 Open the socket and start accepting tasks.
 
None start_accepting (self)
 Start accepting tasks.
 
None stop_accepting (self)
 Stop accepting tasks without closing the accepting socket.
 
None stop (self)
 Stop accepting tasks, close all the sockets.
 
None sockets_close (self, *typing.Optional[int] count=None)
 Close all the connection going through the gate.
 
Address get_sockname_for_clients (self)
 Returns the client socket address that the gate listens on.
 
str info (self)
 Print info on open sockets.
 
None set_to_server_interceptor (self, Interceptor interceptor)
 Replace existing interceptor of client to server data with a custom.
 
None set_to_client_interceptor (self, Interceptor interceptor)
 Replace existing interceptor of server to client data with a custom.
 
None to_server_pass (self)
 Pass data as is.
 
None to_client_pass (self)
 Pass data as is.
 
None to_server_noop (self)
 Do not read data, causing client to keep multiple data.
 
None to_client_noop (self)
 Do not read data, causing server to keep multiple data.
 
None to_server_drop (self)
 Read and discard data.
 
None to_client_drop (self)
 Read and discard data.
 
None to_server_delay (self, float delay)
 Delay data transmission.
 
None to_client_delay (self, float delay)
 Delay data transmission.
 
None to_server_close_on_data (self)
 Close on first bytes of data from client.
 
None to_client_close_on_data (self)
 Close on first bytes of data from server.
 
None to_server_corrupt_data (self)
 Corrupt data received from client.
 
None to_client_corrupt_data (self)
 Corrupt data received from server.
 
None to_server_limit_bps (self, float bytes_per_second)
 Limit bytes per second transmission by network from client.
 
None to_client_limit_bps (self, float bytes_per_second)
 Limit bytes per second transmission by network from server.
 
None to_server_limit_time (self, float timeout, float jitter)
 Limit connection lifetime on receive of first bytes from client.
 
None to_client_limit_time (self, float timeout, float jitter)
 Limit connection lifetime on receive of first bytes from server.
 
None to_server_smaller_parts (self, int max_size, *float sleep_per_packet=0)
 Pass data to server in smaller parts.
 
None to_client_smaller_parts (self, int max_size, *float sleep_per_packet=0)
 Pass data to client in smaller parts.
 
None to_server_concat_packets (self, int packet_size)
 Pass data in bigger parts.
 
None to_client_concat_packets (self, int packet_size)
 Pass data in bigger parts.
 
None to_server_limit_bytes (self, int bytes_limit)
 Drop all connections each bytes_limit of data sent by network.
 
None to_client_limit_bytes (self, int bytes_limit)
 Drop all connections each bytes_limit of data sent by network.
 
None to_server_substitute (self, str pattern, str repl)
 Apply regex substitution to data from client.
 
None to_client_substitute (self, str pattern, str repl)
 Apply regex substitution to data from server.
 

Protected Member Functions

None _make_socket_nonblocking (self, Socket sock)
 
typing.List[Socket] _create_accepting_sockets (self)
 
 _connect_to_server (self)
 
None _do_accept (self, Socket accept_sock)
 This task should wait for connections and create SocketPair.
 
- Protected Member Functions inherited from pytest_userver.chaos.BaseGate
None _collect_garbage (self)
 

Protected Attributes

 _sockets
 
 _loop
 
 _to_server_intercept
 
 _to_client_intercept
 
- Protected Attributes inherited from pytest_userver.chaos.BaseGate
 _route
 
 _loop
 
 _connected_event
 
 _NOT_IMPLEMENTED_MESSAGE
 
 _accept_tasks
 
 _sockets
 
 _to_server_intercept
 
 _to_client_intercept
 

Additional Inherited Members

- Static Protected Attributes inherited from pytest_userver.chaos.BaseGate
tuple _NOT_IMPLEMENTED_MESSAGE
 

Constructor & Destructor Documentation

◆ __init__()

None pytest_userver.chaos.TcpGate.__init__ ( self,
GateRoute route,
EvLoop loop )

Reimplemented from pytest_userver.chaos.BaseGate.

Definition at line 764 of file chaos.py.

Member Function Documentation

◆ _connect_to_server()

pytest_userver.chaos.TcpGate._connect_to_server ( self)
protected

Definition at line 823 of file chaos.py.

◆ _create_accepting_sockets()

typing.List[Socket] pytest_userver.chaos.TcpGate._create_accepting_sockets ( self)
protected

Reimplemented from pytest_userver.chaos.BaseGate.

Definition at line 803 of file chaos.py.

◆ _do_accept()

None pytest_userver.chaos.TcpGate._do_accept ( self,
Socket accept_sock )
protected

This task should wait for connections and create SocketPair.

Reimplemented from pytest_userver.chaos.BaseGate.

Definition at line 840 of file chaos.py.

◆ _make_socket_nonblocking()

None pytest_userver.chaos.TcpGate._make_socket_nonblocking ( self,
Socket sock )
protected

Definition at line 798 of file chaos.py.

◆ connections_count()

int pytest_userver.chaos.TcpGate.connections_count ( self)

Returns maximal amount of connections going through the gate at the moment.

Warning
Some of the connections could be closing, or could be opened right before the function starts. Use with caution!

Definition at line 767 of file chaos.py.

◆ wait_for_connections()

None pytest_userver.chaos.TcpGate.wait_for_connections ( self,
* count = 1,
timeout = 0.0 )

Wait for at least count connections going through the gate.

Exceptions
asyncio.TimeoutErrorexception if failed to get the required amount of connections in time.

Definition at line 777 of file chaos.py.

Member Data Documentation

◆ _loop

pytest_userver.chaos.TcpGate._loop
protected

Definition at line 850 of file chaos.py.

◆ _sockets

pytest_userver.chaos.TcpGate._sockets
protected

Definition at line 775 of file chaos.py.

◆ _to_client_intercept

pytest_userver.chaos.TcpGate._to_client_intercept
protected

Definition at line 854 of file chaos.py.

◆ _to_server_intercept

pytest_userver.chaos.TcpGate._to_server_intercept
protected

Definition at line 853 of file chaos.py.


The documentation for this class was generated from the following file: