### Mirakuru Quick Start Example Source: https://github.com/dbfixtures/mirakuru/blob/main/README.rst Demonstrates how to use Mirakuru's TCPExecutor to start a Redis server and wait for it to be ready. ```APIDOC ## Mirakuru Quick Start Example ### Description This example shows how to use `TCPExecutor` to start a Redis server and ensure it's ready to accept connections before proceeding. ### Method N/A (Illustrative Example) ### Endpoint N/A ### Parameters N/A ### Request Example ```python from mirakuru import TCPExecutor # Start Redis server and wait until it accepts connections on port 6379 redis_executor = TCPExecutor('redis-server', host='localhost', port=6379) redis_executor.start() # Redis is now running and ready to accept connections # ... your code that uses Redis here ... # Clean up - stop the Redis server redis_executor.stop() ``` ### Response N/A ### Response Example N/A ``` -------------------------------- ### HTTPExecutor: Full Integration Test Example Source: https://context7.com/dbfixtures/mirakuru/llms.txt An example of a full integration test using HTTPExecutor to start a server and then verifying its responsiveness with a GET request. It ensures the server is running before proceeding. ```python from mirakuru import HTTPExecutor from http.client import HTTPConnection, OK def test_my_api(): executor = HTTPExecutor("./http_server", url="http://127.0.0.1:6543/") executor.start() # Server is guaranteed to be running now conn = HTTPConnection("127.0.0.1", 6543) conn.request("GET", "/") assert conn.getresponse().status == OK executor.stop() ``` -------------------------------- ### Start and manage Redis with TCPExecutor Source: https://github.com/dbfixtures/mirakuru/blob/main/README.rst Example demonstrating how to use Mirakuru's TCPExecutor to start a Redis server and wait until it's ready to accept TCP connections on a specific port. It also shows how to stop the process. ```python from mirakuru import TCPExecutor # Start Redis server and wait until it accepts connections on port 6379 redis_executor = TCPExecutor('redis-server', host='localhost', port=6379) redis_executor.start() # Redis is now running and ready to accept connections # ... your code that uses Redis here ... # Clean up - stop the Redis server redis_executor.stop() ``` -------------------------------- ### Start a process and wait for a banner with OutputExecutor Source: https://github.com/dbfixtures/mirakuru/blob/main/README.rst Shows how to use OutputExecutor to start a process and monitor its standard output for a specific text banner. The process is considered ready only after this banner appears, ensuring the process has initialized correctly. ```python from mirakuru import OutputExecutor process = OutputExecutor('my_special_process', banner='processed!') process.start() # Here you can do your stuff, e.g. communicate with the started process process.stop() # What happens during start here, is that the executor constantly checks output # produced by started process, and looks for the banner part occurring within the # output. # Once the output is identified, as in example `processed!` is found in output. # It is considered as started, and executor releases your script from wait to work. ``` -------------------------------- ### HTTPExecutor Integration Test Example Source: https://github.com/dbfixtures/mirakuru/blob/main/README.rst An example demonstrating the integration of HTTPExecutor in a test scenario. It starts an HTTP server, verifies its responsiveness, and then stops it. ```python from mirakuru import HTTPExecutor from http.client import HTTPConnection, OK def test_it_works(): # The ``./http_server`` here launches some HTTP server on the 6543 port, # but naturally it is not immediate and takes a non-deterministic time: executor = HTTPExecutor("./http_server", url="http://127.0.0.1:6543/") # Start the server and wait for it to run (blocking): executor.start() # Here the server should be running! conn = HTTPConnection("127.0.0.1", 6543) conn.request("GET", "/") assert conn.getresponse().status is OK executor.stop() ``` -------------------------------- ### Start a process with SimpleExecutor Source: https://github.com/dbfixtures/mirakuru/blob/main/README.rst Demonstrates the basic usage of SimpleExecutor to start a process without waiting for any specific readiness signal. This is useful for processes that don't have a clear indicator of readiness or when readiness is not critical. ```python from mirakuru import SimpleExecutor process = SimpleExecutor('my_special_process') process.start() # Here you can do your stuff, e.g. communicate with the started process process.stop() ``` -------------------------------- ### Start and Stop Process with PidExecutor Source: https://github.com/dbfixtures/mirakuru/blob/main/README.rst Demonstrates the usage of PidExecutor, which starts a process and waits for a specified file to be created before returning control. This is useful for processes that signal readiness by creating a .pid file. ```python from mirakuru import PidExecutor process = PidExecutor('my_special_process', filename='/var/msp/my_special_process.pid') process.start() # Here you can do your stuff, e.g. communicate with the started process process.stop() ``` -------------------------------- ### Method Chaining with SimpleExecutor Source: https://github.com/dbfixtures/mirakuru/blob/main/README.rst Shows an example of method chaining with SimpleExecutor. This allows for inlining operations like starting, stopping, and accessing output in a single statement. ```python from mirakuru import SimpleExecutor command_stdout = SimpleExecutor('my_special_process').start().stop().output ``` -------------------------------- ### Start and Stop Process with HTTPExecutor Source: https://github.com/dbfixtures/mirakuru/blob/main/README.rst Demonstrates the basic usage of HTTPExecutor to start and stop a web service. It initializes the executor with a process name and a URL for readiness checks, then starts and stops the process. ```python from mirakuru import HTTPExecutor process = HTTPExecutor('my_special_process', url='http://localhost:6543/status') process.start() # Here you can do your stuff, e.g. communicate with the started process process.stop() ``` -------------------------------- ### Start a process and wait for TCP connection with TCPExecutor Source: https://github.com/dbfixtures/mirakuru/blob/main/README.rst Illustrates using TCPExecutor to start a process that communicates over TCP. This executor verifies startup by attempting to connect to a specified host and port, ensuring the process is ready to accept connections before proceeding. ```python from mirakuru import TCPExecutor process = TCPExecutor('my_special_process', host='localhost', port=1234) ``` -------------------------------- ### OutputExecutor: Context Manager Usage Source: https://context7.com/dbfixtures/mirakuru/llms.txt Illustrates using OutputExecutor as a context manager, which automatically handles starting and stopping the process. The example shows asserting the running state within the context. ```python from mirakuru import OutputExecutor # Context manager usage with Flask-like app with OutputExecutor('./flask_app.py', banner=r'Running on http://') as app: assert app.running() is True # Flask app is ready and serving requests ``` -------------------------------- ### Install Mirakuru using pip Source: https://github.com/dbfixtures/mirakuru/blob/main/README.rst This command installs the mirakuru library using pip, making it available for use in your Python projects. ```bash pip install mirakuru ``` -------------------------------- ### PidExecutor: Custom Daemon Example with Context Manager Source: https://context7.com/dbfixtures/mirakuru/llms.txt Shows how to use PidExecutor as a context manager for a custom daemon that creates a PID file. It also demonstrates accessing the PID file and its content within the context. ```python from mirakuru import PidExecutor import os # Custom daemon example with PidExecutor('./my_daemon --pidfile /tmp/my.pid', filename='/tmp/my.pid') as daemon: assert daemon.running() is True # Read the PID if needed with open(daemon.filename) as f: pid = int(f.read().strip()) print(f"Daemon running with PID: {pid}") ``` -------------------------------- ### OutputExecutor: Accessing Output After Start Source: https://context7.com/dbfixtures/mirakuru/llms.txt Shows how to retrieve the output stream from an OutputExecutor after it has started. The `output()` method returns a file-like object that can be read to access captured stdout. ```python from mirakuru import OutputExecutor # Access the output after start executor = OutputExecutor('echo "Ready to serve"', banner='Ready') executor.start() output = executor.output() # Returns file-like object for stdout if output: remaining_output = output.read() executor.stop() ``` -------------------------------- ### OutputExecutor Source: https://github.com/dbfixtures/mirakuru/blob/main/README.rst Starts a process and waits for a specific text marker in its output to confirm readiness. ```APIDOC ## OutputExecutor ### Description The `OutputExecutor` starts a process and monitors its standard output for a specific text marker (banner). The process is considered ready only after this marker appears. ### Method N/A (Illustrative Example) ### Endpoint N/A ### Parameters N/A ### Request Example ```python from mirakuru import OutputExecutor process = OutputExecutor('my_special_process', banner='processed!') process.start() # Here you can do your stuff, e.g. communicate with the started process process.stop() ``` ### Response N/A ### Response Example N/A ``` -------------------------------- ### UnixSocketExecutor: PostgreSQL with Unix Socket Source: https://context7.com/dbfixtures/mirakuru/llms.txt An example of using UnixSocketExecutor to manage a PostgreSQL server instance that communicates via a Unix domain socket. It specifies the command to start PostgreSQL and the expected socket name. ```python from mirakuru import UnixSocketExecutor # PostgreSQL with Unix socket pg_executor = UnixSocketExecutor( command='postgres -D /var/lib/postgresql/data -k /tmp', socket_name='/tmp/.s.PGSQL.5432' ) ``` -------------------------------- ### TCPExecutor Source: https://github.com/dbfixtures/mirakuru/blob/main/README.rst Starts a process and verifies readiness by attempting to establish a TCP connection. ```APIDOC ## TCPExecutor ### Description The `TCPExecutor` is designed for processes that communicate over TCP connections. It starts the process and attempts to connect to a specified host and port to confirm that the process is accepting connections. Once a successful connection is made, the process is considered ready. ### Method N/A (Illustrative Example) ### Endpoint N/A ### Parameters N/A ### Request Example ```python from mirakuru import TCPExecutor process = TCPExecutor('my_special_process', host='localhost', port=1234) # The process will start and control will return only after a successful connection to localhost:1234 process.start() ``` ### Response N/A ### Response Example N/A ``` -------------------------------- ### PidExecutor: Wait for Daemon PID File Creation Source: https://context7.com/dbfixtures/mirakuru/llms.txt This example demonstrates using PidExecutor to wait for a process to create a specific PID file. This is a common pattern for traditional Unix daemons to signal they are ready. ```python from mirakuru import PidExecutor import os # Wait for daemon to create its PID file executor = PidExecutor( command='/usr/sbin/nginx', filename='/var/run/nginx.pid', timeout=30 ) executor.start() # Nginx has created its PID file and is ready executor.stop() ``` -------------------------------- ### Using HTTPExecutor as a Context Manager Source: https://github.com/dbfixtures/mirakuru/blob/main/README.rst Demonstrates how to use HTTPExecutor as a context manager. The process starts upon entering the 'with' block and stops automatically upon exiting it, ensuring proper resource management. ```python from mirakuru import HTTPExecutor with HTTPExecutor('my_special_process', url='http://localhost:6543/status') as process: # Here you can do your stuff, e.g. communicate with the started process assert process.running() is True assert process.running() is False ``` -------------------------------- ### PidExecutor: Integration Test for Daemon Service Source: https://context7.com/dbfixtures/mirakuru/llms.txt An integration test scenario using PidExecutor to start a daemon and verify that its PID file is created and the executor reports the process as running. Includes cleanup of old PID files. ```python from mirakuru import PidExecutor import os # Integration test for a daemon service def test_daemon_service(): pid_file = '/tmp/test_daemon.pid' # Clean up any existing PID file if os.path.exists(pid_file): os.remove(pid_file) executor = PidExecutor( command=f'./test_daemon --pid {pid_file}', filename=pid_file, timeout=10 ) executor.start() assert os.path.isfile(pid_file) assert executor.running() is True executor.stop() ``` -------------------------------- ### OutputExecutor: Monitor stderr Instead of stdout Source: https://context7.com/dbfixtures/mirakuru/llms.txt This example shows how to configure OutputExecutor to monitor the standard error stream (stderr) instead of the standard output (stdout) for the banner. This is useful when startup messages are directed to stderr. ```python from mirakuru import OutputExecutor # Monitor stderr instead of stdout executor = OutputExecutor( command='./my_process', banner='Initialization complete', stdout=None, # Don't capture stdout stderr=-1 # subprocess.PIPE for stderr ) executor.start() executor.stop() ``` -------------------------------- ### Release Versioning with tbump Source: https://github.com/dbfixtures/mirakuru/blob/main/CONTRIBUTING.rst This command is used to manage the release version of the mirakuru project. It requires pipenv to be installed for managing development dependencies. Replace '[NEW_VERSION]' with the actual version number. ```bash pipenv run tbump [NEW_VERSION] ``` -------------------------------- ### SimpleExecutor Source: https://github.com/dbfixtures/mirakuru/blob/main/README.rst The base executor for starting and stopping processes without checking for readiness. ```APIDOC ## SimpleExecutor ### Description The `SimpleExecutor` starts a process and reports it as running without verifying its readiness. It serves as the base class for other executors. ### Method N/A (Illustrative Example) ### Endpoint N/A ### Parameters N/A ### Request Example ```python from mirakuru import SimpleExecutor process = SimpleExecutor('my_special_process') process.start() # Here you can do your stuff, e.g. communicate with the started process process.stop() ``` ### Response N/A ### Response Example N/A ``` -------------------------------- ### HTTPExecutor: Custom HTTP Method with Payload and Headers Source: https://context7.com/dbfixtures/mirakuru/llms.txt Demonstrates using HTTPExecutor to send a POST request with a custom payload and headers to a specified URL. It includes starting and stopping the executor. ```python from mirakuru import HTTPExecutor executor = HTTPExecutor( command='./api_server', url='http://localhost:9000/api/ping', method='POST', payload={'action': 'healthcheck'}, headers={'Content-Type': 'application/x-www-form-urlencoded', 'Authorization': 'Bearer token'}, timeout=60 ) executor.start() executor.stop() ``` -------------------------------- ### UnixSocketExecutor: Custom Unix Socket Server with Client Connection Source: https://context7.com/dbfixtures/mirakuru/llms.txt Demonstrates using UnixSocketExecutor as a context manager for a custom Unix socket server. It also includes a client example that connects to the socket, sends data, and receives a response. ```python from mirakuru import UnixSocketExecutor # Custom Unix socket server with UnixSocketExecutor('./my_socket_server', socket_name='/tmp/my.sock') as server: assert server.running() is True # Server is listening on Unix socket import socket client = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) client.connect('/tmp/my.sock') client.send(b'hello') response = client.recv(1024) client.close() ``` -------------------------------- ### UnixSocketExecutor: Wait for Docker Daemon Socket Source: https://context7.com/dbfixtures/mirakuru/llms.txt This snippet shows how to use UnixSocketExecutor to wait for the Docker daemon to become available by checking its Unix domain socket. It includes the command to start the daemon and the socket name. ```python from mirakuru import UnixSocketExecutor # Wait for Docker daemon socket executor = UnixSocketExecutor( command='dockerd', socket_name='/var/run/docker.sock', timeout=60 ) executor.start() # Docker daemon is accepting connections executor.stop() ``` -------------------------------- ### HTTPExecutor with Custom Request Method Source: https://github.com/dbfixtures/mirakuru/blob/main/README.rst Illustrates changing the HTTP request method used by HTTPExecutor for readiness checks. By default, it uses HEAD, but can be configured to use GET, POST, or other methods via the 'method' argument. ```python from mirakuru import HTTPExecutor process = HTTPExecutor('my_special_process', url='http://localhost:6543/status', status='(200|404)', method='GET') process.start() ``` -------------------------------- ### Server Control and State Verification with Mirakuru Source: https://context7.com/dbfixtures/mirakuru/llms.txt Demonstrates how to temporarily stop a server using a context manager, verify its running state, and then restart and clean up the server. ```python from mirakuru import Server # Assuming 'server' is an instance of a Mirakuru Server class # Temporarily stop for failure testing with server.stopped(): # Server is stopped here - test client behavior during outage assert server.running() is False # Test reconnection logic, circuit breakers, etc. # Server automatically restarted assert server.running() is True # Clean up server.stop() ``` -------------------------------- ### OutputExecutor: Using Regex Pattern for Flexible Matching Source: https://context7.com/dbfixtures/mirakuru/llms.txt Demonstrates using a regular expression pattern with OutputExecutor to match a more flexible startup message. This allows for variations in the output, such as timing information. ```python from mirakuru import OutputExecutor # Using regex pattern for flexible matching executor = OutputExecutor( command='java -jar myapp.jar', banner=r'Started.*in \d+ seconds', # Matches "Started MyApp in 3 seconds" timeout=120 ) ``` -------------------------------- ### Mirakuru Exception Handling for Process Failures Source: https://context7.com/dbfixtures/mirakuru/llms.txt Illustrates how to use Mirakuru's specific exceptions like TimeoutExpired, AlreadyRunning, and ProcessExitedWithError to handle various process startup and execution failures gracefully. ```python from mirakuru import ( TCPExecutor, HTTPExecutor, TimeoutExpired, AlreadyRunning, ProcessExitedWithError, ) # Handle timeout when process takes too long to start try: executor = TCPExecutor('slow_server', host='localhost', port=5000, timeout=5) executor.start() except TimeoutExpired as e: print(f"Server failed to start within {e.timeout} seconds") print(f"Executor: {e.executor}") # Handle case when port is already in use try: executor = TCPExecutor('redis-server', host='localhost', port=6379) executor.start() except AlreadyRunning as e: print(f"Port already in use: {e}") # Another process is already listening on the port # Handle process crash during startup try: executor = HTTPExecutor('./buggy_server', url='http://localhost:8080/') executor.start() except ProcessExitedWithError as e: print(f"Process crashed with exit code: {e.exit_code}") print(f"Executor: {e.executor}") # Comprehensive error handling example def start_service_safely(command, host, port): executor = TCPExecutor(command, host=host, port=port, timeout=30) try: executor.start() return executor except AlreadyRunning: print(f"Service already running on {host}:{port}") return None except TimeoutExpired: print(f"Service failed to start in time") return None except ProcessExitedWithError as e: print(f"Service crashed: exit code {e.exit_code}") return None ``` -------------------------------- ### Manage Processes with SimpleExecutor Source: https://context7.com/dbfixtures/mirakuru/llms.txt SimpleExecutor provides basic process lifecycle management without readiness checks. It supports context managers, command lists, and custom environment configurations. ```python from mirakuru import SimpleExecutor # Basic usage with start/stop process = SimpleExecutor('python -m http.server 8000') process.start() assert process.running() is True process.stop() # Using as context manager for automatic cleanup with SimpleExecutor('python -m http.server 8000') as process: assert process.running() is True # Configure custom working directory and environment variables process = SimpleExecutor( command='./my_script.sh', cwd='/path/to/working/dir', envvars={'MY_VAR': 'value', 'DEBUG': '1'}, timeout=60, sleep=0.1 ) ``` -------------------------------- ### OutputExecutor: Wait for Specific Startup Message Source: https://context7.com/dbfixtures/mirakuru/llms.txt This snippet shows how to use OutputExecutor to wait for a specific text string (banner) to appear in the process's standard output. It's useful for services that print a clear startup confirmation. ```python from mirakuru import OutputExecutor # Wait for specific startup message executor = OutputExecutor( command='python my_server.py', banner='Server started successfully' ) executor.start() # Process has printed "Server started successfully" executor.stop() ``` -------------------------------- ### Advanced Mirakuru Executor Configuration Source: https://context7.com/dbfixtures/mirakuru/llms.txt Demonstrates extensive configuration options for Mirakuru executors, including timeouts, signals, environment variables, working directories, and subprocess I/O handling. It also shows how to access process attributes and manage process lifecycle. ```python from mirakuru import TCPExecutor, SimpleExecutor import signal import subprocess # Full configuration example executor = TCPExecutor( command=['./my_server', '--port', '8080'], host='localhost', port=8080, # Timeout and polling timeout=60, sleep=0.5, # Process control signals stop_signal=signal.SIGTERM, kill_signal=signal.SIGKILL, expected_returncode=0, # Environment and working directory cwd='/app', envvars={'NODE_ENV': 'test', 'LOG_LEVEL': 'debug'}, # Subprocess I/O configuration stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=False, # Additional popen kwargs popen_kwargs={'start_new_session': True} ) # Access process attributes executor.start() print(f"Command: {executor.command}") print(f"Process PID: {executor.process.pid}") print(f"Running: {executor.running()}") # Get process output stdout = executor.output() # stdout file object stderr = executor.err_output() # stderr file object # Custom wait conditions def custom_check(): # Your custom readiness check logic return True executor.wait_for(custom_check) # Method chaining output = SimpleExecutor('echo "test"').start().stop().output() # Stop with different signal executor.stop(stop_signal=signal.SIGINT, expected_returncode=-2) # Force kill executor.kill(wait=True, sig=signal.SIGKILL) ``` -------------------------------- ### Exception Handling Source: https://context7.com/dbfixtures/mirakuru/llms.txt Details on how to handle process lifecycle exceptions such as timeouts, port conflicts, and process crashes. ```APIDOC ## Exception Handling ### Description Mirakuru provides specific exceptions for different failure scenarios, enabling precise error handling in your tests. ### Exceptions - **TimeoutExpired**: Raised when the process fails to start or stop within the specified timeout period. - **AlreadyRunning**: Raised when the target port or resource is already in use by another process. - **ProcessExitedWithError**: Raised when the subprocess terminates unexpectedly with a non-zero exit code. ### Usage Example ```python try: executor = TCPExecutor('service', host='localhost', port=5000, timeout=5) executor.start() except TimeoutExpired as e: print(f"Server failed to start within {e.timeout} seconds") except AlreadyRunning as e: print(f"Port already in use: {e}") except ProcessExitedWithError as e: print(f"Process crashed with exit code: {e.exit_code}") ``` ``` -------------------------------- ### Context Manager stopped(): Temporarily Stop and Restart Process Source: https://context7.com/dbfixtures/mirakuru/llms.txt Illustrates the use of the `stopped()` context manager with HTTPExecutor. This allows for temporarily stopping a running process and ensuring it restarts upon exiting the context, useful for testing resilience. ```python from mirakuru import HTTPExecutor # Start the server server = HTTPExecutor('./api_server', url='http://localhost:8000/health') server.start() assert server.running() is True # Example usage of stopped() context manager would go here ``` -------------------------------- ### HTTPExecutor with Custom Status Codes Source: https://github.com/dbfixtures/mirakuru/blob/main/README.rst Shows how to configure HTTPExecutor to accept specific HTTP status codes as indicators of readiness. The 'status' argument can be an integer or a regular expression string. ```python from mirakuru import HTTPExecutor process = HTTPExecutor('my_special_process', url='http://localhost:6543/status', status='(200|404)') process.start() ``` -------------------------------- ### Advanced Executor Configuration Source: https://context7.com/dbfixtures/mirakuru/llms.txt Configuration options for process signals, environment variables, I/O handling, and custom readiness checks. ```APIDOC ## Advanced Executor Configuration ### Description Executors support extensive configuration for signals, timeouts, environment variables, working directories, and subprocess I/O handling. ### Configuration Parameters - **command** (list/str) - Required - The command to execute. - **timeout** (int) - Optional - Max seconds to wait for start/stop. - **stop_signal** (signal) - Optional - Signal used for graceful shutdown. - **envvars** (dict) - Optional - Environment variables for the subprocess. - **stdin/stdout/stderr** (subprocess.PIPE) - Optional - I/O stream configuration. ### Example ```python executor = TCPExecutor( command=['./my_server', '--port', '8080'], timeout=60, stop_signal=signal.SIGTERM, envvars={'NODE_ENV': 'test'}, stdout=subprocess.PIPE ) executor.start() ``` ``` -------------------------------- ### Stopping Process within a Context Manager Source: https://github.com/dbfixtures/mirakuru/blob/main/README.rst Illustrates how to use the '.stopped()' context manager to stop a process temporarily. The process is stopped upon entering the context and restarted upon exiting it. ```python from mirakuru import HTTPExecutor process = HTTPExecutor('my_special_process', url='http://localhost:6543/status').start() # Here you can do your stuff, e.g. communicate with the started process with process.stopped(): # Here you will not be able to communicate with the process as it is killed here assert process.running() is False assert process.running() is True ``` -------------------------------- ### TCPExecutor Command Definition Source: https://github.com/dbfixtures/mirakuru/blob/main/README.rst Shows two ways to define the command for TCPExecutor: as a single string or as a list of strings. This flexibility allows for commands with arguments and spaces. ```python # command as string TCPExecutor('python -m smtpd -n -c DebuggingServer localhost:1025', host='localhost', port=1025) ``` ```python # command as list TCPExecutor( ['python', '-m', 'smtpd', '-n', '-c', 'DebuggingServer', 'localhost:1025'], host='localhost', port=1025 ) ``` -------------------------------- ### Orchestrate TCP Services with TCPExecutor Source: https://context7.com/dbfixtures/mirakuru/llms.txt TCPExecutor verifies process readiness by attempting to establish a TCP connection to a specified host and port. This is ideal for databases and background services like Redis or PostgreSQL. ```python from mirakuru import TCPExecutor from signal import SIGTERM, SIGKILL # Start Redis and wait until it accepts connections redis_executor = TCPExecutor( command='redis-server', host='localhost', port=6379, timeout=30 ) redis_executor.start() redis_executor.stop() # Using context manager for PostgreSQL with TCPExecutor('postgres -D /var/lib/postgresql/data', host='localhost', port=5432) as pg: print(f"Connected to {pg.host}:{pg.port}") # With custom signals for stop and kill executor = TCPExecutor( 'memcached -p 11211', host='127.0.0.1', port=11211, stop_signal=SIGTERM, kill_signal=SIGKILL, expected_returncode=0 ) ``` -------------------------------- ### Verify HTTP Services with HTTPExecutor Source: https://context7.com/dbfixtures/mirakuru/llms.txt HTTPExecutor extends TCP connectivity checks by performing HTTP requests to confirm service readiness. It supports status code validation via exact matches or regex patterns. ```python from mirakuru import HTTPExecutor # Basic HTTP server - waits for 2XX response by default with HTTPExecutor('./start_web_server.sh', url='http://localhost:8080/') as server: assert server.running() is True # Specify exact status code or regex pattern api_server = HTTPExecutor( command='python app.py', url='http://localhost:5000/health', status=200 ) api_server.start() api_server.stop() # Using regex for multiple acceptable status codes executor = HTTPExecutor( 'node server.js', url='http://localhost:3000/status', status='(200|204|304)' ) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.