I'm looking for best practices or the recommended approach to test async code execution with Karate.
Our use cases are all pretty similar but a basic one is:
- Client makes HTTP request to API
- API accepts request and creates a messages which is added to a queue
- API replies with ACCEPTED / 202
- Worker picks up message from queue processes it and updates database
- Eventually after the work is finished another endpoint delivers updated data
How can I check with Karate that after processing has finished other endpoints return the correct result?
Concrete real life example:
- Client requests a processing intensive data export to API e.g. via HTTP POST
/api/export
- API create message with information for creating the export and puts it on AWS SQS queue
- API replies with 202
- Worker receives message and creates export, uploads result as ZIP to S3 and finally creates and entry in the database symbolizing this export
- Client can now query list exports endpoint e.g. via HTTP GET /api/exports
- API returns 200 with the list of exports incl. the newly created entry
Generally I have two ideas on how to approach this:
- Use karate
retry until
on the endpoint that returns the list of exports - In the API response (step #3) return the message ID and use the HTTP API of SQS to poll that endpoint until the message has been processed and then query the list endpoint to check the result
Is either of those approach recommended or should I choose an entirely different solution?