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 838 of file chaos.py.

+ Inheritance diagram for pytest_userver.chaos.TcpGate:

Public Member Functions

None __init__ (self, GateRoute route, typing.Optional[EvLoop] loop=None)
 
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.
 
'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.
 
callinfo.AsyncCallQueue set_to_server_interceptor (self, Interceptor interceptor)
 Replace existing interceptor of client to server data with a custom.
 
callinfo.AsyncCallQueue set_to_client_interceptor (self, Interceptor interceptor)
 Replace existing interceptor of server to client data with a custom.
 
callinfo.AsyncCallQueue to_server_pass (self)
 Pass data as is.
 
callinfo.AsyncCallQueue to_client_pass (self)
 Pass data as is.
 
callinfo.AsyncCallQueue to_server_noop (self)
 Do not read data, causing client to keep multiple data.
 
callinfo.AsyncCallQueue to_client_noop (self)
 Do not read data, causing server to keep multiple data.
 
callinfo.AsyncCallQueue to_server_drop (self)
 Read and discard data.
 
callinfo.AsyncCallQueue to_client_drop (self)
 Read and discard data.
 
callinfo.AsyncCallQueue to_server_delay (self, float delay)
 Delay data transmission.
 
callinfo.AsyncCallQueue to_client_delay (self, float delay)
 Delay data transmission.
 
callinfo.AsyncCallQueue to_server_close_on_data (self)
 Close on first bytes of data from client.
 
callinfo.AsyncCallQueue to_client_close_on_data (self)
 Close on first bytes of data from server.
 
callinfo.AsyncCallQueue to_server_corrupt_data (self)
 Corrupt data received from client.
 
callinfo.AsyncCallQueue to_client_corrupt_data (self)
 Corrupt data received from server.
 
callinfo.AsyncCallQueue to_server_limit_bps (self, float bytes_per_second)
 Limit bytes per second transmission by network from client.
 
callinfo.AsyncCallQueue to_client_limit_bps (self, float bytes_per_second)
 Limit bytes per second transmission by network from server.
 
callinfo.AsyncCallQueue to_server_limit_time (self, float timeout, float jitter)
 Limit connection lifetime on receive of first bytes from client.
 
callinfo.AsyncCallQueue to_client_limit_time (self, float timeout, float jitter)
 Limit connection lifetime on receive of first bytes from server.
 
callinfo.AsyncCallQueue to_server_smaller_parts (self, int max_size, *, float sleep_per_packet=0)
 Pass data to server in smaller parts.
 
callinfo.AsyncCallQueue to_client_smaller_parts (self, int max_size, *, float sleep_per_packet=0)
 Pass data to client in smaller parts.
 
callinfo.AsyncCallQueue to_server_concat_packets (self, int packet_size)
 Pass data in bigger parts.
 
callinfo.AsyncCallQueue to_client_concat_packets (self, int packet_size)
 Pass data in bigger parts.
 
callinfo.AsyncCallQueue to_server_limit_bytes (self, int bytes_limit)
 Drop all connections each bytes_limit of data sent by network.
 
callinfo.AsyncCallQueue to_client_limit_bytes (self, int bytes_limit)
 Drop all connections each bytes_limit of data sent by network.
 
callinfo.AsyncCallQueue to_server_substitute (self, str pattern, str repl)
 Apply regex substitution to data from client.
 
callinfo.AsyncCallQueue to_client_substitute (self, str pattern, str repl)
 Apply regex substitution to data from server.
 

Protected Member Functions

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.
 
None _collect_garbage (self)
 

Protected Attributes

 _connected_event = asyncio.Event()
 
 _route = route
 
 _loop = loop
 
Interceptor _to_server_intercept = _intercept_ok
 
Interceptor _to_client_intercept = _intercept_ok
 
list _accept_sockets = []
 
list _accept_tasks = []
 
typing.Set[_SocketsPaired] _sockets = set()
 

Static Protected Attributes

str _NOT_IMPLEMENTED_MESSAGE = 'Do not use BaseGate itself, use one of specializations TcpGate or UdpGate'
 

Constructor & Destructor Documentation

◆ __init__()

None pytest_userver.chaos.TcpGate.__init__ ( self,
GateRoute route,
typing.Optional[EvLoop] loop = None )

Definition at line 849 of file chaos.py.

Member Function Documentation

◆ __aenter__()

'BaseGate' pytest_userver.chaos.BaseGate.__aenter__ ( self)
inherited

Definition at line 517 of file chaos.py.

◆ __aexit__()

None pytest_userver.chaos.BaseGate.__aexit__ ( self,
exc_type,
exc_value,
traceback )
inherited

Definition at line 521 of file chaos.py.

◆ _collect_garbage()

None pytest_userver.chaos.BaseGate._collect_garbage ( self)
protectedinherited

Definition at line 618 of file chaos.py.

◆ _connect_to_server()

pytest_userver.chaos.TcpGate._connect_to_server ( self)
protected

Definition at line 904 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 885 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 921 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 853 of file chaos.py.

◆ get_sockname_for_clients()

Address pytest_userver.chaos.BaseGate.get_sockname_for_clients ( self)
inherited

Returns the client socket address that the gate listens on.

This function allows to use 0 in GateRoute.port_for_client and retrieve the actual port and host.

Definition at line 601 of file chaos.py.

◆ info()

str pytest_userver.chaos.BaseGate.info ( self)
inherited

Print info on open sockets.

Definition at line 611 of file chaos.py.

◆ set_to_client_interceptor()

callinfo.AsyncCallQueue pytest_userver.chaos.BaseGate.set_to_client_interceptor ( self,
Interceptor interceptor )
inherited

Replace existing interceptor of server to client data with a custom.

Definition at line 636 of file chaos.py.

◆ set_to_server_interceptor()

callinfo.AsyncCallQueue pytest_userver.chaos.BaseGate.set_to_server_interceptor ( self,
Interceptor interceptor )
inherited

Replace existing interceptor of client to server data with a custom.

Definition at line 627 of file chaos.py.

◆ sockets_close()

None pytest_userver.chaos.BaseGate.sockets_close ( self,
* ,
typing.Optional[int] count = None )
inherited

Close all the connection going through the gate.

Definition at line 591 of file chaos.py.

◆ start()

pytest_userver.chaos.BaseGate.start ( self)
inherited

Open the socket and start accepting tasks.

Definition at line 527 of file chaos.py.

◆ start_accepting()

None pytest_userver.chaos.BaseGate.start_accepting ( self)
inherited

Start accepting tasks.

Definition at line 551 of file chaos.py.

◆ stop()

None pytest_userver.chaos.BaseGate.stop ( self)
inherited

Stop accepting tasks, close all the sockets.

Definition at line 571 of file chaos.py.

◆ stop_accepting()

None pytest_userver.chaos.BaseGate.stop_accepting ( self)
inherited

Stop accepting tasks without closing the accepting socket.

Definition at line 563 of file chaos.py.

◆ to_client_close_on_data()

callinfo.AsyncCallQueue pytest_userver.chaos.BaseGate.to_client_close_on_data ( self)
inherited

Close on first bytes of data from server.

Definition at line 710 of file chaos.py.

◆ to_client_concat_packets()

callinfo.AsyncCallQueue pytest_userver.chaos.BaseGate.to_client_concat_packets ( self,
int packet_size )
inherited

Pass data in bigger parts.

Parameters
packet_sizeminimal size of the resulting packet

Reimplemented in pytest_userver.chaos.UdpGate.

Definition at line 801 of file chaos.py.

◆ to_client_corrupt_data()

callinfo.AsyncCallQueue pytest_userver.chaos.BaseGate.to_client_corrupt_data ( self)
inherited

Corrupt data received from server.

Definition at line 720 of file chaos.py.

◆ to_client_delay()

callinfo.AsyncCallQueue pytest_userver.chaos.BaseGate.to_client_delay ( self,
float delay )
inherited

Delay data transmission.

Definition at line 692 of file chaos.py.

◆ to_client_drop()

callinfo.AsyncCallQueue pytest_userver.chaos.BaseGate.to_client_drop ( self)
inherited

Read and discard data.

Definition at line 674 of file chaos.py.

◆ to_client_limit_bps()

callinfo.AsyncCallQueue pytest_userver.chaos.BaseGate.to_client_limit_bps ( self,
float bytes_per_second )
inherited

Limit bytes per second transmission by network from server.

Definition at line 733 of file chaos.py.

◆ to_client_limit_bytes()

callinfo.AsyncCallQueue pytest_userver.chaos.BaseGate.to_client_limit_bytes ( self,
int bytes_limit )
inherited

Drop all connections each bytes_limit of data sent by network.

Definition at line 814 of file chaos.py.

◆ to_client_limit_time()

callinfo.AsyncCallQueue pytest_userver.chaos.BaseGate.to_client_limit_time ( self,
float timeout,
float jitter )
inherited

Limit connection lifetime on receive of first bytes from server.

Definition at line 750 of file chaos.py.

◆ to_client_noop()

callinfo.AsyncCallQueue pytest_userver.chaos.BaseGate.to_client_noop ( self)
inherited

Do not read data, causing server to keep multiple data.

Definition at line 664 of file chaos.py.

◆ to_client_pass()

callinfo.AsyncCallQueue pytest_userver.chaos.BaseGate.to_client_pass ( self)
inherited

Pass data as is.

Definition at line 654 of file chaos.py.

◆ to_client_smaller_parts()

callinfo.AsyncCallQueue pytest_userver.chaos.BaseGate.to_client_smaller_parts ( self,
int max_size,
* ,
float sleep_per_packet = 0 )
inherited

Pass data to client in smaller parts.

Parameters
max_sizeMax packet size to send to client
sleep_per_packetOptional sleep interval per packet, seconds

Reimplemented in pytest_userver.chaos.UdpGate.

Definition at line 776 of file chaos.py.

◆ to_client_substitute()

callinfo.AsyncCallQueue pytest_userver.chaos.BaseGate.to_client_substitute ( self,
str pattern,
str repl )
inherited

Apply regex substitution to data from server.

Definition at line 828 of file chaos.py.

◆ to_server_close_on_data()

callinfo.AsyncCallQueue pytest_userver.chaos.BaseGate.to_server_close_on_data ( self)
inherited

Close on first bytes of data from client.

Definition at line 705 of file chaos.py.

◆ to_server_concat_packets()

callinfo.AsyncCallQueue pytest_userver.chaos.BaseGate.to_server_concat_packets ( self,
int packet_size )
inherited

Pass data in bigger parts.

Parameters
packet_sizeminimal size of the resulting packet

Reimplemented in pytest_userver.chaos.UdpGate.

Definition at line 793 of file chaos.py.

◆ to_server_corrupt_data()

callinfo.AsyncCallQueue pytest_userver.chaos.BaseGate.to_server_corrupt_data ( self)
inherited

Corrupt data received from client.

Definition at line 715 of file chaos.py.

◆ to_server_delay()

callinfo.AsyncCallQueue pytest_userver.chaos.BaseGate.to_server_delay ( self,
float delay )
inherited

Delay data transmission.

Definition at line 679 of file chaos.py.

◆ to_server_drop()

callinfo.AsyncCallQueue pytest_userver.chaos.BaseGate.to_server_drop ( self)
inherited

Read and discard data.

Definition at line 669 of file chaos.py.

◆ to_server_limit_bps()

callinfo.AsyncCallQueue pytest_userver.chaos.BaseGate.to_server_limit_bps ( self,
float bytes_per_second )
inherited

Limit bytes per second transmission by network from client.

Definition at line 725 of file chaos.py.

◆ to_server_limit_bytes()

callinfo.AsyncCallQueue pytest_userver.chaos.BaseGate.to_server_limit_bytes ( self,
int bytes_limit )
inherited

Drop all connections each bytes_limit of data sent by network.

Definition at line 809 of file chaos.py.

◆ to_server_limit_time()

callinfo.AsyncCallQueue pytest_userver.chaos.BaseGate.to_server_limit_time ( self,
float timeout,
float jitter )
inherited

Limit connection lifetime on receive of first bytes from client.

Definition at line 741 of file chaos.py.

◆ to_server_noop()

callinfo.AsyncCallQueue pytest_userver.chaos.BaseGate.to_server_noop ( self)
inherited

Do not read data, causing client to keep multiple data.

Definition at line 659 of file chaos.py.

◆ to_server_pass()

callinfo.AsyncCallQueue pytest_userver.chaos.BaseGate.to_server_pass ( self)
inherited

Pass data as is.

Definition at line 649 of file chaos.py.

◆ to_server_smaller_parts()

callinfo.AsyncCallQueue pytest_userver.chaos.BaseGate.to_server_smaller_parts ( self,
int max_size,
* ,
float sleep_per_packet = 0 )
inherited

Pass data to server in smaller parts.

Parameters
max_sizeMax packet size to send to server
sleep_per_packetOptional sleep interval per packet, seconds

Reimplemented in pytest_userver.chaos.UdpGate.

Definition at line 759 of file chaos.py.

◆ to_server_substitute()

callinfo.AsyncCallQueue pytest_userver.chaos.BaseGate.to_server_substitute ( self,
str pattern,
str repl )
inherited

Apply regex substitution to data from client.

Definition at line 819 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 863 of file chaos.py.

Member Data Documentation

◆ _accept_sockets

list pytest_userver.chaos.BaseGate._accept_sockets = []
protectedinherited

Definition at line 512 of file chaos.py.

◆ _accept_tasks

pytest_userver.chaos.BaseGate._accept_tasks = []
protectedinherited

Definition at line 513 of file chaos.py.

◆ _connected_event

pytest_userver.chaos.TcpGate._connected_event = asyncio.Event()
protected

Definition at line 850 of file chaos.py.

◆ _loop

pytest_userver.chaos.BaseGate._loop = loop
protectedinherited

Definition at line 507 of file chaos.py.

◆ _NOT_IMPLEMENTED_MESSAGE

pytest_userver.chaos.BaseGate._NOT_IMPLEMENTED_MESSAGE = 'Do not use BaseGate itself, use one of specializations TcpGate or UdpGate'
staticprotectedinherited

Definition at line 501 of file chaos.py.

◆ _route

pytest_userver.chaos.BaseGate._route = route
protectedinherited

Definition at line 504 of file chaos.py.

◆ _sockets

pytest_userver.chaos.BaseGate._sockets = set()
protectedinherited

Definition at line 515 of file chaos.py.

◆ _to_client_intercept

pytest_userver.chaos.BaseGate._to_client_intercept = _intercept_ok
protectedinherited

Definition at line 510 of file chaos.py.

◆ _to_server_intercept

pytest_userver.chaos.BaseGate._to_server_intercept = _intercept_ok
protectedinherited

Definition at line 509 of file chaos.py.


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