Basic testing
The simplest way to test your handler is by running it directly with test input.Inline JSON
Pass test input directly via the command line:Test file
For more complex or reusable test inputs, create atest_input.json file in the same directory as your handler:
test_input.json
test_input.json file.
If you provide both a
test_input.json file and the --test_input flag, the command-line input takes precedence.Local API server
For more comprehensive testing, start a local API server that simulates your Serverless endpoint. This lets you send HTTP requests to test your handler as if it were deployed. Start the local server:http://localhost:8000.
Send requests to the server
Once your local server is running, send HTTPPOST requests from another terminal to test your function:
The
/run endpoint only returns a fake request ID without executing your code, since async mode requires communication with Runpod’s system. For local testing, use /runsync to execute your handler and get results immediately.Testing concurrency
The local API server runs as a single process and handles every request on one event loop. To test how your handler behaves when several requests arrive at once, write it as anasync function and send overlapping requests to the server. An async handler that awaits I/O works on overlapping requests at the same time, while a synchronous handler processes them one after another.
The --rp_api_concurrency flag doesn’t start more server processes. If you set it above 1, the server logs a warning and starts a single worker process.
Testing concurrent requests
Send multiple requests simultaneously to test concurrency:Handling concurrency in your code
If your handler uses shared state (like global variables), use proper synchronization to avoid race conditions:Debugging
Log levels
Control the verbosity of console output with the--rp_log_level flag:
ERROR: Only show error messages.WARN: Show warnings and errors.INFO: Show general information, warnings, and errors.DEBUG: Show all messages, including detailed debug information.
Enable the debugger
Use the--rp_debugger flag for detailed troubleshooting:
Server configuration
Customize the local API server with these flags:Port
Set a custom port (default is 8000):Host
Set the hostname (default is “localhost”):Flag reference
Here’s a complete reference of all available flags for local testing:Combined example
You can combine multiple flags to create a customized local testing environment:- Starts the local API server on port 8080.
- Sets the log level to
DEBUGfor maximum information. - Enables the debugger for troubleshooting.