Hello
I have a Node.js app running on my local machine that publishes to a pub/sub topic. I’m currently using the Pub/Sub emulator Docker image to receive the messages so I don’t use the actual service.
I want to test a scenario where Pub/Sub has a big latency in receiving my messages and throws a timeout error.
How can I simulate such a scenario? Is there any extra configuration I can add to the pub/sub simulator to make it fail on purpose?
Thanks
You may use a network simulation tool that can introduce latency or packet loss between your app and the emulator. If you are on Linux, you can use tc.
1 Like
Thanks for the suggestion.
Since I’m using a Docker image for the pub/sub emulator that is based on Debian I was able to install the tc command using apt-get install iproute2
I was able to introduce a general latency for all requests using this command tc qdisc add dev lo root netem delay 10000ms and remove the latency when I didn’t need it anymore using tc qdisc del dev lo root
I just had to make sure to run the latency command after a connection was made from the Node app to the simulator and after all topics and subscriptions were created in the simulator.
So far I was able to test the scenarios where the service is unresponsive and test the built-in retry logic in the client library.
Thanks for the help
1 Like
You’re welcome and great job!