components-contrib/tests/certification/state/sqlite
Josh van Leeuwen 9be6d157a4
tests/certification: Updates dapr/dapr to `master` HEAD (#3084)
Signed-off-by: joshvanl <me@joshvanl.dev>
Co-authored-by: Bernd Verst <github@bernd.dev>
2023-08-21 17:06:55 -07:00
..
artifacts WIP 2023-02-03 20:09:40 +00:00
resources WIP: certification test 2023-02-03 01:41:02 +00:00
README.md Improved concurrency test 2023-02-04 18:44:27 +00:00
config.yaml WIP: certification test 2023-02-03 01:41:02 +00:00
sqlite_test.go tests/certification: Updates dapr/dapr to `master` HEAD (#3084) 2023-08-21 17:06:55 -07:00

README.md

SQLite State Store certification testing

This project aims to test the SQLite State Store component under various conditions.

To run these tests:

go test -v -tags certtests -count=1 .

Test plan

Basic tests (in-memory)

Uses an in-memory, temporary database.

  1. Creates a new, in-memory database and initializes the tables.
  2. Able to do set, get, update and delete.

SQL Injection

  1. Not prone to SQL injection on write
  2. Not prone to SQL injection on read
  3. Not prone to SQL injection on delete

Read-only databases

  1. Open an existing database in read-only mode
  2. Attempt basic CRUD tests: get operations succeed; set, update, delete fail.
  3. Stop the Dapr sidecar and verify that the database file was not modified on-disk.

This also tests the ability to use connection strings that don't start with file:

TTLs and cleanups

Also tests the tableName and metadataTableName metadata properties.

  1. Correctly parse the cleanupIntervalInSeconds metadata property:
    • No value uses the default value (disabled)
    • A positive value sets the interval
    • A zero or negative value disables the cleanup
  2. The cleanup method deletes expired records and updates the metadata table with the last time it ran
  3. The cleanup method doesn't run if the last iteration was less than cleanupIntervalInSeconds or if another process is doing the cleanup

Initialization and migrations

Also tests the tableName and metadataTableName metadata properties.

  1. Initializes the component with names for tables that don't exist
  2. Initializes the component with all migrations performed (current level is "1")
  3. Initializes the component with only the state table, created before the metadata table was added (implied migration level "1")
  4. Initializes three components at the same time and ensure no race conditions exist in performing migrations

Concurrency

  1. Test concurrency using a single connection (single component)
    1. Using 10 parallel goroutines, write to a key in the database (unique per goroutine), then retrieve the value and ensure it's the one that was just stored
    2. Using 10 parallel goroutines, write to the same key multiple times; at the end of the writes, ensure the last value written is the one in the database
  2. Test concurrency using a 3 connections (3 components)
    1. Using 10 parallel goroutines selecting from the 3 connections, write to a key in the database (unique per goroutine), then retrieve the value and ensure it's the one that was just stored
    2. Using 10 parallel goroutines selecting from the 3 connections, write to the same key multiple times; at the end of the writes, ensure the last value written is the one in the database