This is a minimal setup to reproduce specific behavior and issues with Cloud Functions and Pub/Sub topics on the Firebase emulator.
- Docker and Docker Compose
- Make
-
Start the environment:
make compose
This will automatically detect your platform (Mac/Linux) and start all required services.
-
Run the tests:
make test
- First test will fail: Pub/Sub seems to lose the first message for some reason when the emulator is just started
- Second test will succeed: The test that updates 100 products should work properly
- Tests fail randomly: The emulator appears to kill functions after 30 seconds regardless of configuration, breaking tests
If you check the console and see that functions have ended like this:
firebase-1 | i functions: Finished "europe-west4-products_sync_bulk" in 29054.191729ms
firebase-1 | i functions: Finished "europe-west4-products_sync_bulk" in 29056.899779ms
firebase-1 | i functions: Finished "europe-west4-products_sync_bulk" in 29055.842414ms
firebase-1 | i functions: Finished "europe-west4-products_sync_bulk" in 29057.540609ms
firebase-1 | i functions: Finished "europe-west4-products_sync_bulk" in 29058.24203ms
firebase-1 | i functions: Finished "europe-west4-products_sync_bulk" in 29056.543984ms
firebase-1 | i functions: Finished "europe-west4-products_sync_bulk" in 29051.259175ms
firebase-1 | i functions: Finished "europe-west4-products_sync_bulk" in 29010.059986ms
Then running the tests again should result in both tests passing.
In our full test suite, we sometimes see unexplained random errors such as:
firebase Connection in use: ('127.0.0.1', 8996)
Error: socket hang up
ERRCONNRESET
function failed to load
The @pubsub_fn
decorator creates many instances on the emulator, despite being configured with:
min_instances=1,
max_instances=1,
concurrency=1,
Question: Please verify this behavior against the expected implementation. Should the emulator respect these instance limits?
Functions appear to be terminated after approximately 30 seconds regardless of the configured timeout, causing test failures when run consecutively.
functions/python/
- Cloud Functions codefunctions/python/app/tests/
- Test suitedocker-compose.yaml
- Service configurationMakefile
- Build and test commands