'Cosmos Emulator randomly failing tests on Linux

I'm trying to run Cosmos Emulator on Linux, to run tests using SpecFlow.

After installing it following these instructions, and successfully running it, a variable number of tests randomly failed all the times I tried to run them.

The failed tests throw a CosmosException with a 503 (Service Unavailable) status code.

All these tests work just fine on Windows and, depending on how I run them, either via the terminal or VSCode, the number of failures differs.



Solution 1:[1]

The problem was with the docker command provided within the documentation:

docker run -p 8081:8081 -p 10251:10251 -p 10252:10252 -p 10253:10253 -p 10254:10254  -m 3g --cpus=2.0 --name=test-linux-emulator -e AZURE_COSMOS_EMULATOR_PARTITION_COUNT=10 -e AZURE_COSMOS_EMULATOR_ENABLE_DATA_PERSISTENCE=true -e AZURE_COSMOS_EMULATOR_IP_ADDRESS_OVERRIDE=$ipaddr -it mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator

More specifically, with this environment variable:

AZURE_COSMOS_EMULATOR_PARTITION_COUNT=10

This partition count was too low, which caused it to drop requests. Increasing it to 20, as suggested in this Github thread, solved the issue.

I also increased the --cpus to 3.0 and the memory -m to 4g, just to be safe.

EDIT: Ended up having to increase to 40. It never broke again after that.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1