Bridge Integrity — Integration Testing Strategy for EventBridge Based Serverless Architectures

Introduction

A generic scenario to test…

A diagram of 2 services which are connected via EventBridge. The first service creates and order and the second service writes and invoice to S3.
EventBridge makes it easy to create loosely coupled event driven architectures because the services don’t need to be aware of each other

Testing Strategies

A diagram to show the 3 ways of testing, unit, integration and end to end. End to end is slower and more expensive. End to end testing should come last in the CI process.
COMMENT
A diagram showing the flow split into 2 integration tests. The Order Service is tested by the first test and the Payments service is tested by the second

The Need for Ephemeral Test Stacks

The CI process from opening a pull request to tearing down the ephemeral stack.
Serverless Flow — The CI process from opening a pull request to tearing down the ephemeral stack.

Assert the event was fired

Diagram to show we are focussing on the first integration test
  • The waitTimeSeconds being defined as > 0s defines the difference between long and short polling

Assert Received

Diagram to show that we are now focussing on the second integration test

Conclusion

  • Using short lived test stacks to match the production environment
  • Combining Jest with the AWS SDK to run tests and make assertions
  • Using Jest custom matchers to create readable full stack Serverless assertions
  • Creation of an event interceptor rule on EventBridge to forward events to SQS via infrastructure as code or direct calls to the AWS SDK
  • Asserting that events have been fired via long polling on the SQS queue
  • Asserting the correct behaviour when events are received through event injection via the AWS SDK

--

--

Tools, techniques, and case studies of using serverless to release fast and scale optimally.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store