Automating Database Testing in Your CI/CD Pipelines

A presentation at GitHub Tel Aviv User Group in December 2024 in Tel Aviv-Yafo, Israel by Ben Greenberg

Slide 1

Slide 1

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.

Slide 2

Slide 2

@hummusonrails ‹#›

Slide 3

Slide 3

The Rebel Alliance needs the @hummusonrails ‹#›

Slide 4

Slide 4

Your database needs @hummusonrails ‹#›

Slide 5

Slide 5

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 ‹#›

Slide 6

Slide 6

Why test your database? ‹#›

Slide 7

Slide 7

Do. Or do not. There is only try. ‹#›

Slide 8

Slide 8

Testing your database ensures: 1.Data integrity 2.Data reliability It’s a critical part of your software development lifecycle @hummusonrails ‹#›

Slide 9

Slide 9

Challenges do exist ‹#›

Slide 10

Slide 10

Concurrency Issues @hummusonrails @hummusonrails ‹#›

Slide 11

Slide 11

What happens when multiple database operations are executed simultaneously? @hummusonrails ‹#›

Slide 12

Slide 12

Challenges • Deadlocks • Race conditions • Performance degradation @hummusonrails @hummusonrails ‹#›

Slide 13

Slide 13

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 ‹#›

Slide 14

Slide 14

Race Conditions Imagine two operations: Two users updating the same inventory count in a shopping site at the same time. @hummusonrails @hummusonrails ‹#›

Slide 15

Slide 15

Performance Degradation It’s Black Friday and the site is under heavy load. Can it handle the influx of write operations? @hummusonrails @hummusonrails ‹#›

Slide 16

Slide 16

Data Consistency @hummusonrails @hummusonrails ‹#›

Slide 17

Slide 17

Do all users see the same data being accessed at the same time? @hummusonrails ‹#›

Slide 18

Slide 18

Challenges • Read operations • Write operations • Replication delays @hummusonrails ‹#›

Slide 19

Slide 19

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 ‹#›

Slide 20

Slide 20

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 ‹#›

Slide 21

Slide 21

How do we overcome these challenges? ‹#›

Slide 22

Slide 22

Types of database tests ‹#›

Slide 23

Slide 23

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.

Slide 24

Slide 24

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.

Slide 25

Slide 25

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.

Slide 26

Slide 26

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.

Slide 27

Slide 27

Automating Database Testing ‹#›

Slide 28

Slide 28

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.

Slide 29

Slide 29

@hummusonrails @hummusonrails ‹#› Confidential and Proprietary. Do not distribute without Couchbase consent. © Couchbase 2024. All rights reserved.

Slide 30

Slide 30

@hummusonrails ‹#›

Slide 31

Slide 31

‹#›

Slide 32

Slide 32

‹#› @hummusonrails Confidential and Proprietary. Do not distribute without Couchbase consent. © Couchbase 2024. All rights reserved.

Slide 33

Slide 33

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. ‹#›

Slide 34

Slide 34

Support for @hummusonrails ‹#›

Slide 35

Slide 35

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 ‹#›

Slide 36

Slide 36

• New PR • New Commit • • • • Unit Integration End-to-end Load • Logging and analytics • Deploy to: @hummusonrails ‹#›

Slide 37

Slide 37

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 ‹#›

Slide 38

Slide 38

GitHub Action Setup @hummusonrails ‹#›

Slide 39

Slide 39

GitHub Action Workflow Define the trigger Set up environment: • Node.js • Docker • Install dependencies Define Actions secrets variables Run the test @hummusonrails ‹#›

Slide 40

Slide 40

@hummusonrails @hummusonrails Confidential and Proprietary. Do not distribute without Couchbase consent. © Couchbase 2024. All rights reserved. ‹#›

Slide 41

Slide 41

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 ‹#›

Slide 42

Slide 42

‹#› @hummusonrails

Slide 43

Slide 43

@hummusonrails @hummusonrails Confidential and Proprietary. Do not distribute without Couchbase consent. © Couchbase 2024. All rights reserved. ‹#›

Slide 44

Slide 44

A Note On ‹#›

Slide 45

Slide 45

” 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. ‹#›

Slide 46

Slide 46

Database Logs and Metrics Improve… @hummusonrails @hummusonrails Confidential and Proprietary. Do not distribute without Couchbase consent. © Couchbase 2024. All rights reserved. ‹#›

Slide 47

Slide 47

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. ‹#›

Slide 48

Slide 48

Visualizing the Workflow ‹#› @hummusonrails Confidential and Proprietary. Do not distribute without Couchbase consent. © Couchbase 2024. All rights reserved. @hummusonrails

Slide 49

Slide 49

You don’t have to build it alone… @hummusonrails @hummusonrails Confidential and Proprietary. Do not distribute without Couchbase consent. © Couchbase 2024. All rights reserved. ‹#›

Slide 50

Slide 50

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. ‹#›

Slide 51

Slide 51

@hummusonrails @hummusonrails Confidential and Proprietary. Do not distribute without Couchbase consent. © Couchbase 2024. All rights reserved. ‹#›

Slide 52

Slide 52

@hummusonrails @hummusonrails Confidential and Proprietary. Do not distribute without Couchbase consent. © Couchbase 2024. All rights reserved. ‹#›

Slide 53

Slide 53

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.

Slide 54

Slide 54

‹#› @hummusonrails Confidential and Proprietary. Do not distribute without Couchbase consent. © Couchbase 2024. All rights reserved.

Slide 55

Slide 55

Thank you! ben.greenberg@couchbase.com @hummusonrails ‹#›