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
To test how your handler performs under parallel execution, use the--rp_api_concurrency flag to set the number of concurrent workers.
This command starts your local server with 4 concurrent workers:
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.
- Uses 4 concurrent workers.
- Sets the log level to
DEBUGfor maximum information. - Enables the debugger for troubleshooting.