A presentation at GitHub Tel Aviv User Group in in Tel Aviv-Yafo, Israel by Ben Greenberg
Automating Database Testing in Your CI/CD Pipelines Ben Greenberg, Senior Developer Advocate @hummusonrails Confidential and Proprietary. Do not distribute without Couchbase consent. © Couchbase 2024. All rights reserved.
@hummusonrails ‹#›
The Rebel Alliance needs the @hummusonrails ‹#›
Your database needs @hummusonrails ‹#›
What we’re going to talk about • Why test your database? What are the unique challenges in DB testing? • Types of database tests. • Automating with • A word on @hummusonrails ‹#›
Why test your database? ‹#›
Do. Or do not. There is only try. ‹#›
Testing your database ensures: 1.Data integrity 2.Data reliability It’s a critical part of your software development lifecycle @hummusonrails ‹#›
Challenges do exist ‹#›
Concurrency Issues @hummusonrails @hummusonrails ‹#›
What happens when multiple database operations are executed simultaneously? @hummusonrails ‹#›
Challenges • Deadlocks • Race conditions • Performance degradation @hummusonrails @hummusonrails ‹#›
Deadlocks Imagine two transactions: One locking a customer record and the other locking an order record, both waiting for the other to finish first. @hummusonrails @hummusonrails ‹#›
Race Conditions Imagine two operations: Two users updating the same inventory count in a shopping site at the same time. @hummusonrails @hummusonrails ‹#›
Performance Degradation It’s Black Friday and the site is under heavy load. Can it handle the influx of write operations? @hummusonrails @hummusonrails ‹#›
Data Consistency @hummusonrails @hummusonrails ‹#›
Do all users see the same data being accessed at the same time? @hummusonrails ‹#›
Challenges • Read operations • Write operations • Replication delays @hummusonrails ‹#›
Replication Delays User updates their profile. Data is being replicated across nodes. Will User B see User A’s updated profile or the old one? @hummusonrails @hummusonrails ‹#›
Read/Write Anomalies Bank account balance shows an old value during a transaction. Conflict when multiple writes target the same data. Inconsistent data is read due to ongoing writes. @hummusonrails ‹#›
How do we overcome these challenges? ‹#›
Types of database tests ‹#›
Unit Tests Individual Components Focus on the different components of the database Example: Testing document upsert functionality ‹#› @hummusonrails Confidential and Proprietary. Do not distribute without Couchbase consent. © Couchbase 2024. All rights reserved.
Integration Tests Working Together Ensuring different parts of the database work together Example: Testing document flow ‹#› @hummusonrails Confidential and Proprietary. Do not distribute without Couchbase consent. © Couchbase 2024. All rights reserved.
End-to-end Tests Is it all working? Making sure the whole application works from the user’s perspective. Example: Testing an ecommerce platform ‹#› @hummusonrails Confidential and Proprietary. Do not distribute without Couchbase consent. © Couchbase 2024. All rights reserved.
Load Tests Real world load Identifying performance bottlenecks. Example: Testing multiple transactions simultaneously ‹#› @hummusonrails Confidential and Proprietary. Do not distribute without Couchbase consent. © Couchbase 2024. All rights reserved.
Automating Database Testing ‹#›
Why do it manually? When you can automate it! @hummusonrails @hummusonrails ‹#› Confidential and Proprietary. Do not distribute without Couchbase consent. © Couchbase 2024. All rights reserved.
@hummusonrails @hummusonrails ‹#› Confidential and Proprietary. Do not distribute without Couchbase consent. © Couchbase 2024. All rights reserved.
@hummusonrails ‹#›
‹#›
‹#› @hummusonrails Confidential and Proprietary. Do not distribute without Couchbase consent. © Couchbase 2024. All rights reserved.
Spin Up Realistic Test Environments for CI/CD Workflows @hummusonrails @hummusonrails Confidential and Proprietary. Do not distribute without Couchbase consent. © Couchbase 2024. All rights reserved. ‹#›
Support for @hummusonrails ‹#›
1.CI/CD Trigger 2.Spin Up Environment 3.Initialize DB Connection 4.Run Tests 5.Generate Results 6.Pass/Fail Decision 7.Deploy to Production 8.Send Alerts/Logs 9.Terminate Env @hummusonrails 10.Complete Process ‹#›
• New PR • New Commit • • • • Unit Integration End-to-end Load • Logging and analytics • Deploy to: @hummusonrails ‹#›
Unit Test with Include the correct dependency container Initialize connection to database in BEFORE block Close connection to database in AFTER block Run the actual test @hummusonrails ‹#›
GitHub Action Setup @hummusonrails ‹#›
GitHub Action Workflow Define the trigger Set up environment: • Node.js • Docker • Install dependencies Define Actions secrets variables Run the test @hummusonrails ‹#›
@hummusonrails @hummusonrails Confidential and Proprietary. Do not distribute without Couchbase consent. © Couchbase 2024. All rights reserved. ‹#›
GitHub Action Workflow with Cloud Offloading container execution from your test environment Instead of initializing a Docker container directly inside your GitHub Actions environment @hummusonrails ‹#›
‹#› @hummusonrails
@hummusonrails @hummusonrails Confidential and Proprietary. Do not distribute without Couchbase consent. © Couchbase 2024. All rights reserved. ‹#›
A Note On ‹#›
” provides a collection of APIs, SDKs, and ” tools to standardize telemetry data (metrics, logs, and traces) collection and export ” @hummusonrails @hummusonrails Confidential and Proprietary. Do not distribute without Couchbase consent. © Couchbase 2024. All rights reserved. ‹#›
Database Logs and Metrics Improve… @hummusonrails @hummusonrails Confidential and Proprietary. Do not distribute without Couchbase consent. © Couchbase 2024. All rights reserved. ‹#›
ean time to detection oot cause analysis ean time to resolution @hummusonrails Confidential and Proprietary. Do not distribute without Couchbase consent. © Couchbase 2024. All rights reserved. ‹#›
Visualizing the Workflow ‹#› @hummusonrails Confidential and Proprietary. Do not distribute without Couchbase consent. © Couchbase 2024. All rights reserved. @hummusonrails
You don’t have to build it alone… @hummusonrails @hummusonrails Confidential and Proprietary. Do not distribute without Couchbase consent. © Couchbase 2024. All rights reserved. ‹#›
OTel Workflow Example: Using an OTel Exporter Marketplace Action with Database Test Metrics and Traces @hummusonrails Confidential and Proprietary. Do not distribute without Couchbase consent. © Couchbase 2024. All rights reserved. @hummusonrails Confidential and Proprietary. Do not distribute without Couchbase consent. © Couchbase 2024. All rights reserved. ‹#›
@hummusonrails @hummusonrails Confidential and Proprietary. Do not distribute without Couchbase consent. © Couchbase 2024. All rights reserved. ‹#›
@hummusonrails @hummusonrails Confidential and Proprietary. Do not distribute without Couchbase consent. © Couchbase 2024. All rights reserved. ‹#›
Want to learn more? DB Testing with GitHub Actions @hummusonrails Testcontainers in GitHub Actions ‹#› Confidential and Proprietary. Do not distribute without Couchbase consent. © Couchbase 2024. All rights reserved.
‹#› @hummusonrails Confidential and Proprietary. Do not distribute without Couchbase consent. © Couchbase 2024. All rights reserved.
Thank you! ben.greenberg@couchbase.com @hummusonrails ‹#›
This talk will guide you through the essentials of integrating comprehensive database testing and monitoring into your CI/CD pipelines. We’ll explore the types of tests you should run, from unit to performance tests, and demonstrate how to automate these processes using GitHub Actions. Testing databases involves unique challenges such as ensuring data consistency, handling stateful interactions, and dealing with various concurrency issues. We’ll also touch upon and briefly show how to share your GitHub Actions workflow data with monitoring tools like Prometheus, and what aspects of your workflow data you should share to maintain a healthy and performant database. Join us to learn how to elevate your CI/CD workflows and achieve more holistic database management.