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

Detailed Description

Implements UDP chaos-proxy logic such as demuxing incoming datagrams from different clients.

Separate connections to server are made for each new client.

See also
Chaos Testing

Definition at line 946 of file chaos.py.

+ Inheritance diagram for pytest_userver.chaos.UdpGate:

Public Member Functions

 __init__ (self, GateRoute route, EvLoop|None loop=None)
 
bool is_connected (self)
 Returns True if there is active pair of sockets ready to transfer data at the moment.
 
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_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.
 
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, *, int|None 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_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

list[Socket] _create_accepting_sockets (self)
 
 _connect_to_server (self)
 
None _collect_garbage (self)
 
 _do_accept (self, Socket accept_sock)
 This task should wait for connections and create SocketPair.
 

Protected Attributes

set[_UdpDemuxSocketMock] _clients = set()
 
 _route = route
 
 _loop = loop
 
Interceptor _to_server_intercept = _intercept_ok
 
Interceptor _to_client_intercept = _intercept_ok
 
list _accept_sockets = []
 
list _accept_tasks = []
 
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__()

pytest_userver.chaos.UdpGate.__init__ ( self,
GateRoute route,
EvLoop | None loop = None )

Definition at line 957 of file chaos.py.

Member Function Documentation

◆ __aenter__()

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

Definition at line 518 of file chaos.py.

◆ __aexit__()

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

Definition at line 522 of file chaos.py.

◆ _collect_garbage()

None pytest_userver.chaos.UdpGate._collect_garbage ( self)
protected

Reimplemented from pytest_userver.chaos.BaseGate.

Definition at line 999 of file chaos.py.

◆ _connect_to_server()

pytest_userver.chaos.UdpGate._connect_to_server ( self)
protected

Definition at line 983 of file chaos.py.

◆ _create_accepting_sockets()

list[Socket] pytest_userver.chaos.UdpGate._create_accepting_sockets ( self)
protected

Reimplemented from pytest_userver.chaos.BaseGate.

Definition at line 968 of file chaos.py.

◆ _do_accept()

pytest_userver.chaos.UdpGate._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 1003 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 602 of file chaos.py.

◆ info()

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

Print info on open sockets.

Definition at line 612 of file chaos.py.

◆ is_connected()

bool pytest_userver.chaos.UdpGate.is_connected ( self)

Returns True if there is active pair of sockets ready to transfer data at the moment.

Definition at line 961 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 637 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 628 of file chaos.py.

◆ sockets_close()

None pytest_userver.chaos.BaseGate.sockets_close ( self,
* ,
int | None count = None )
inherited

Close all the connection going through the gate.

Definition at line 592 of file chaos.py.

◆ start()

pytest_userver.chaos.BaseGate.start ( self)
inherited

Open the socket and start accepting tasks.

Definition at line 528 of file chaos.py.

◆ start_accepting()

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

Start accepting tasks.

Definition at line 552 of file chaos.py.

◆ stop()

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

Stop accepting tasks, close all the sockets.

Definition at line 572 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 564 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 711 of file chaos.py.

◆ to_client_concat_packets()

None pytest_userver.chaos.UdpGate.to_client_concat_packets ( self,
int packet_size )

Pass data in bigger parts.

Parameters
packet_sizeminimal size of the resulting packet

Reimplemented from pytest_userver.chaos.BaseGate.

Definition at line 1040 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 721 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 693 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 675 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 734 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 815 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 751 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 665 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 655 of file chaos.py.

◆ to_client_smaller_parts()

None pytest_userver.chaos.UdpGate.to_client_smaller_parts ( self,
int max_size,
* ,
float sleep_per_packet = 0 )

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 from pytest_userver.chaos.BaseGate.

Definition at line 1051 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 829 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 706 of file chaos.py.

◆ to_server_concat_packets()

None pytest_userver.chaos.UdpGate.to_server_concat_packets ( self,
int packet_size )

Pass data in bigger parts.

Parameters
packet_sizeminimal size of the resulting packet

Reimplemented from pytest_userver.chaos.BaseGate.

Definition at line 1037 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 716 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 680 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 670 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 726 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 810 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 742 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 660 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 650 of file chaos.py.

◆ to_server_smaller_parts()

None pytest_userver.chaos.UdpGate.to_server_smaller_parts ( self,
int max_size,
* ,
float sleep_per_packet = 0 )

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 from pytest_userver.chaos.BaseGate.

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

Member Data Documentation

◆ _accept_sockets

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

Definition at line 513 of file chaos.py.

◆ _accept_tasks

pytest_userver.chaos.BaseGate._accept_tasks = []
protectedinherited

Definition at line 514 of file chaos.py.

◆ _clients

set[_UdpDemuxSocketMock] pytest_userver.chaos.UdpGate._clients = set()
protected

Definition at line 958 of file chaos.py.

◆ _loop

pytest_userver.chaos.BaseGate._loop = loop
protectedinherited

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

◆ _route

pytest_userver.chaos.BaseGate._route = route
protectedinherited

Definition at line 505 of file chaos.py.

◆ _sockets

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

Definition at line 516 of file chaos.py.

◆ _to_client_intercept

pytest_userver.chaos.BaseGate._to_client_intercept = _intercept_ok
protectedinherited

Definition at line 511 of file chaos.py.

◆ _to_server_intercept

pytest_userver.chaos.BaseGate._to_server_intercept = _intercept_ok
protectedinherited

Definition at line 510 of file chaos.py.


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