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

Detailed Description

This base class maintain endpoints of two types:

Server-side endpoints to receive messages from clients. Address of this endpoint is described by (host_for_client, port_for_client).

Client-side endpoints to forward messages to server. Server must listen on (host_to_server, port_to_server).

Asynchronously concurrently passes data from client to server and from server to client, allowing intercepting the data, injecting delays and dropping connections.

Warning
Do not use this class itself. Use one of the specifications TcpGate or UdpGate
See also
Chaos Testing

Definition at line 462 of file chaos.py.

+ Inheritance diagram for pytest_userver.chaos.BaseGate:

Public Member Functions

None __init__ (self, GateRoute route, EvLoop loop)
 
'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

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

Protected Attributes

 _route
 
 _loop
 
 _NOT_IMPLEMENTED_MESSAGE
 
 _accept_tasks
 
 _sockets
 
 _to_server_intercept
 
 _to_client_intercept
 

Static Protected Attributes

tuple _NOT_IMPLEMENTED_MESSAGE
 

Constructor & Destructor Documentation

◆ __init__()

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

Definition at line 489 of file chaos.py.

Member Function Documentation

◆ __aenter__()

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

Definition at line 501 of file chaos.py.

◆ __aexit__()

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

Definition at line 505 of file chaos.py.

◆ _collect_garbage()

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

Definition at line 604 of file chaos.py.

◆ _create_accepting_sockets()

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

Definition at line 508 of file chaos.py.

◆ _do_accept()

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

This task should wait for connections and create SocketPair.

Reimplemented in pytest_userver.chaos.TcpGate, and pytest_userver.chaos.UdpGate.

Definition at line 607 of file chaos.py.

◆ get_sockname_for_clients()

Address pytest_userver.chaos.BaseGate.get_sockname_for_clients ( self)

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

◆ info()

str pytest_userver.chaos.BaseGate.info ( self)

Print info on open sockets.

Definition at line 595 of file chaos.py.

◆ set_to_client_interceptor()

None pytest_userver.chaos.BaseGate.set_to_client_interceptor ( self,
Interceptor interceptor )

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

Definition at line 621 of file chaos.py.

◆ set_to_server_interceptor()

None pytest_userver.chaos.BaseGate.set_to_server_interceptor ( self,
Interceptor interceptor )

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

Definition at line 613 of file chaos.py.

◆ sockets_close()

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

Close all the connection going through the gate.

Definition at line 575 of file chaos.py.

◆ start()

pytest_userver.chaos.BaseGate.start ( self)

Open the socket and start accepting tasks.

Definition at line 511 of file chaos.py.

◆ start_accepting()

None pytest_userver.chaos.BaseGate.start_accepting ( self)

Start accepting tasks.

Definition at line 535 of file chaos.py.

◆ stop()

None pytest_userver.chaos.BaseGate.stop ( self)

Stop accepting tasks, close all the sockets.

Definition at line 555 of file chaos.py.

◆ stop_accepting()

None pytest_userver.chaos.BaseGate.stop_accepting ( self)

Stop accepting tasks without closing the accepting socket.

Definition at line 547 of file chaos.py.

◆ to_client_close_on_data()

None pytest_userver.chaos.BaseGate.to_client_close_on_data ( self)

Close on first bytes of data from server.

Definition at line 686 of file chaos.py.

◆ to_client_concat_packets()

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

Pass data in bigger parts.

Parameters
packet_sizeminimal size of the resulting packet

Reimplemented in pytest_userver.chaos.UdpGate.

Definition at line 765 of file chaos.py.

◆ to_client_corrupt_data()

None pytest_userver.chaos.BaseGate.to_client_corrupt_data ( self)

Corrupt data received from server.

Definition at line 696 of file chaos.py.

◆ to_client_delay()

None pytest_userver.chaos.BaseGate.to_client_delay ( self,
float delay )

Delay data transmission.

Definition at line 670 of file chaos.py.

◆ to_client_drop()

None pytest_userver.chaos.BaseGate.to_client_drop ( self)

Read and discard data.

Definition at line 654 of file chaos.py.

◆ to_client_limit_bps()

None pytest_userver.chaos.BaseGate.to_client_limit_bps ( self,
float bytes_per_second )

Limit bytes per second transmission by network from server.

Definition at line 708 of file chaos.py.

◆ to_client_limit_bytes()

None pytest_userver.chaos.BaseGate.to_client_limit_bytes ( self,
int bytes_limit )

Drop all connections each bytes_limit of data sent by network.

Definition at line 778 of file chaos.py.

◆ to_client_limit_time()

None pytest_userver.chaos.BaseGate.to_client_limit_time ( self,
float timeout,
float jitter )

Limit connection lifetime on receive of first bytes from server.

Definition at line 722 of file chaos.py.

◆ to_client_noop()

None pytest_userver.chaos.BaseGate.to_client_noop ( self)

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

Definition at line 644 of file chaos.py.

◆ to_client_pass()

None pytest_userver.chaos.BaseGate.to_client_pass ( self)

Pass data as is.

Definition at line 634 of file chaos.py.

◆ to_client_smaller_parts()

None pytest_userver.chaos.BaseGate.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 in pytest_userver.chaos.UdpGate.

Definition at line 743 of file chaos.py.

◆ to_client_substitute()

None pytest_userver.chaos.BaseGate.to_client_substitute ( self,
str pattern,
str repl )

Apply regex substitution to data from server.

Definition at line 790 of file chaos.py.

◆ to_server_close_on_data()

None pytest_userver.chaos.BaseGate.to_server_close_on_data ( self)

Close on first bytes of data from client.

Definition at line 681 of file chaos.py.

◆ to_server_concat_packets()

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

Pass data in bigger parts.

Parameters
packet_sizeminimal size of the resulting packet

Reimplemented in pytest_userver.chaos.UdpGate.

Definition at line 757 of file chaos.py.

◆ to_server_corrupt_data()

None pytest_userver.chaos.BaseGate.to_server_corrupt_data ( self)

Corrupt data received from client.

Definition at line 691 of file chaos.py.

◆ to_server_delay()

None pytest_userver.chaos.BaseGate.to_server_delay ( self,
float delay )

Delay data transmission.

Definition at line 659 of file chaos.py.

◆ to_server_drop()

None pytest_userver.chaos.BaseGate.to_server_drop ( self)

Read and discard data.

Definition at line 649 of file chaos.py.

◆ to_server_limit_bps()

None pytest_userver.chaos.BaseGate.to_server_limit_bps ( self,
float bytes_per_second )

Limit bytes per second transmission by network from client.

Definition at line 701 of file chaos.py.

◆ to_server_limit_bytes()

None pytest_userver.chaos.BaseGate.to_server_limit_bytes ( self,
int bytes_limit )

Drop all connections each bytes_limit of data sent by network.

Definition at line 773 of file chaos.py.

◆ to_server_limit_time()

None pytest_userver.chaos.BaseGate.to_server_limit_time ( self,
float timeout,
float jitter )

Limit connection lifetime on receive of first bytes from client.

Definition at line 715 of file chaos.py.

◆ to_server_noop()

None pytest_userver.chaos.BaseGate.to_server_noop ( self)

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

Definition at line 639 of file chaos.py.

◆ to_server_pass()

None pytest_userver.chaos.BaseGate.to_server_pass ( self)

Pass data as is.

Definition at line 629 of file chaos.py.

◆ to_server_smaller_parts()

None pytest_userver.chaos.BaseGate.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 in pytest_userver.chaos.UdpGate.

Definition at line 729 of file chaos.py.

◆ to_server_substitute()

None pytest_userver.chaos.BaseGate.to_server_substitute ( self,
str pattern,
str repl )

Apply regex substitution to data from client.

Definition at line 783 of file chaos.py.

Member Data Documentation

◆ _accept_tasks

pytest_userver.chaos.BaseGate._accept_tasks
protected

Definition at line 538 of file chaos.py.

◆ _loop

pytest_userver.chaos.BaseGate._loop
protected

Definition at line 491 of file chaos.py.

◆ _NOT_IMPLEMENTED_MESSAGE [1/2]

tuple pytest_userver.chaos.BaseGate._NOT_IMPLEMENTED_MESSAGE
staticprotected
Initial value:
= (
'Do not use BaseGate itself, use one of '
'specializations TcpGate or UdpGate'
)

Definition at line 484 of file chaos.py.

◆ _NOT_IMPLEMENTED_MESSAGE [2/2]

pytest_userver.chaos.BaseGate._NOT_IMPLEMENTED_MESSAGE
protected

Definition at line 509 of file chaos.py.

◆ _route

pytest_userver.chaos.BaseGate._route
protected

Definition at line 490 of file chaos.py.

◆ _sockets

pytest_userver.chaos.BaseGate._sockets
protected

Definition at line 579 of file chaos.py.

◆ _to_client_intercept

pytest_userver.chaos.BaseGate._to_client_intercept
protected

Definition at line 625 of file chaos.py.

◆ _to_server_intercept

pytest_userver.chaos.BaseGate._to_server_intercept
protected

Definition at line 617 of file chaos.py.


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