Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Beyond the unit: a holistic approach for testing serverless architectures

Beyond the unit: a holistic approach for testing serverless architectures

One of the peculiar aspects of microservices architecture is the possibility of designing a system as a set of independent but collaborative components. At the root of this collaboration there are well-defined contracts among all the microservices: breaking even a single contract might compromise the health of the entire system. With AWS Lambda, we have the ability to simply create an ever-increasing number of microservices and, therefore, it becomes crucial to find a way to catch errors in advance whenever one of these contracts has been broken.

Mariano Calandra

March 31, 2024
Tweet

More Decks by Mariano Calandra

Other Decks in Programming

Transcript

  1. REDUCE UNPREDICTABILITY BLAST RADIOUS RULE #1 Stop deploying on Friday

    (especially at 5pm)! COROLLARY #1 Start deploying on Tuesday (after the first coffee)!
  2. REDUCE UNPREDICTABILITY BLAST RADIOUS (FOR REAL) OPS SIDE Infrastructure as

    Code, pipelines, progressive deployments... DEV SIDE Tests
  3. UNIT TESTS public class Calculator { public int Sum(int a,

    int b) { return a+b; } } public void TestSum() { // Arrange var calculator = new Calculator(); // Act var result = calculator.Sum(1, 2); // Assert Assert.Equal(3, result); }
  4. MICROSERVICES COMMUNICATION STYLES REQUEST/RESPONSE Checkout Customers GET /customers/5 { ”Id":

    5, "FirstName": "John", "Name": "John", "LastName": "Doe" ”Surname": "Doe” }
  5. UponReceiving("a GET request for a customer") .Given("there is a customer

    with id '5’”) .WithRequest(HttpMethod.Get, "/customers/5") .WillRespond() .WithStatus(HttpStatusCode.OK) .WithJsonBody(new { Id = 5, FirstName = "John", LastName = "Doe” }); CONSUMER DRIVEN CONTRACT TESTING DEFINE CONSUMER EXPECTATIONS
  6. ExpectsToReceive("an ‘order confirmed’ event") .WithJsonContent(new { OrderId = 5, CustomerId

    = 18 }); CONSUMER DRIVEN CONTRACT TESTING DEFINE CONSUMER EXPECTATIONS
  7. .MessagingProvider("Orders") .WithProviderMessages(s => { s.Add("an ‘order confirmed’ event", () =>

    new OrderConfirmedEvent { OrderId = 5, CustomerId = 18, }); }) .WithFileSource(new FileInfo(pactPath)) .Verify(); CONSUMER DRIVEN CONTRACT TESTING VERIFY PROVIDER AGAINST THE CONTRACT
  8. «You don’t choose the moment, The moment chooses you. You

    only choose how prepared you are when it does.»
  9. TAKE AWAY Unit test for testing business logic; Consumer-Driven Contract

    Testing for testing communications; Integration tests can be critical in a serverless environment; Make unpredictable predictable; Further reading (from blog) Why unit tests are not enough when it comes to microservices How chaos engineering will help you design better software
  10. WHO AM I? Mariano Calandra Passionate about architectures and software

    development, work in Var Group as an AWS solutions architect. Co-founder of Serverless Days Rome. Blog Rate the session Careers