Skip to content

fix(serverless): run generator handlers in local test mode - #718

Open
irisfield wants to merge 1 commit into
runpod:mainfrom
irisfield:fix/local-test-generator-handlers
Open

irisfield wants to merge 1 commit into
runpod:mainfrom
irisfield:fix/local-test-generator-handlers

Conversation

@irisfield

Copy link
Copy Markdown

Fixes #717

Problem

Local test mode (--test_input or test_input.json) runs every handler through run_job, so a generator handler is never iterated. The worker and the local API server already branch on is_generator.

Fix

run_local branches on is_generator the same way _sim_runsync does. It iterates run_job_generator, collects the chunks into {"output": [...]}, and stops at the first chunk that carries an error, which the existing error branch logs before exiting 1. The output is always the list of chunks, as in the local API server, because there is no stream endpoint to send them to locally. Non-generator handlers are unchanged.

Tests

Four tests in tests/test_serverless/test_modules/test_local.py, all failing without this change:

  • a sync and an async generator yielding three chunks: the result is {'output': ['chunk 0', 'chunk 1', 'chunk 2']} and the exit code is 0;
  • a generator that yields one chunk and then raises: exit code 1 and the error is logged;
  • a generator whose collected output matches test_output.

Before and after

python handler.py --test_input '{"input":{"x":1}}' with handlers yielding chunk 0 to chunk 2:

Handler 2.1.0 With this change
sync generator Job result: {'output': <generator object handler at 0x...>}, exit 0 Job result: {'output': ['chunk 0', 'chunk 1', 'chunk 2']}, exit 0
async generator Job result: {'output': <async_generator object handler at 0x...>}, exit 0 Job result: {'output': ['chunk 0', 'chunk 1', 'chunk 2']}, exit 0
yields chunk 0, then raises ValueError("boom") completed successfully, exit 0 Job local_test failed with error: handler: boom, exit 1

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Local test mode reports success without running generator handlers

1 participant