Home > Blockchain >  Testing async microservices with no API
Testing async microservices with no API

Time:02-28

We have 5 microservices (more on the way) that communicate with each other asynchronously. 3 of these microservices do not have any API. Those consume data from a message queue, do some processing, and write data into another queue. 2 of these microservices do have APIs, and those also consume data from the queues but send the response back to the caller.

Given that, for testing the service interactions, correctness of contracts, and end-to-end flow:

  • what would be the best way to test the asynchronous services that read from and write to queues?
  • would consumer-contract test be applicable anywhere?
  • I feel end-to-end production testing is possible, but can something more granular and effective be done?

CodePudding user response:

Looks like with Pact it is possible to do message-based contract testing. I think I have a path forward with this.

CodePudding user response:

First, let's correct one thing - you do have APIs. The messages that the "API-less" services read must have some defined content or format. That's an API. You should be testing it, both positive and negative.

Before you get to whole-system testing (in a test or staging environment that mimics your production environment) your testing should probably be in layers, much as in any other system.

  • Unit tests to test the behavior of each class. In your message-handling classes, for example, call each with messages that prompt specific actions and test that it works correctly. These can usually be run very quickly so it's easy to run them often while developing code.
  • Integration tests to make sure your interaction with next-level external systems works. You can use, for example, testcontainers to run isolated instances of the queueing system that your services interact with.

Exactly what form these tests take depends on what languages and frameworks your system is built with. I briefly looked at the Pact tool you referenced and it is taking a similar approach.

  • Related