Skip to main content

Testing

Titan includes a comprehensive integration test suite built with xUnit and Orleans TestCluster. The tests verify Grain logic, state management, database persistence, and distributed multi-silo behavior.

Running Tests

By default, the test script runs both in-memory and database tests:

# Run all tests (in-memory + database)
.\scripts\test.ps1

To run only in-memory tests (faster, no Docker required):

# Run in-memory tests only
.\scripts\test.ps1 -MemoryOnly

Requirements for Database Tests

  • YugabyteDB running via Docker (see Environment Setup)
  • The script automatically sets USE_DATABASE=true for the database run

Test Categories

The test suite is organized into categories using xUnit Traits.

Distributed Tests

Tests that verify multi-silo Orleans behavior using a 2-silo TestCluster:

# Run only distributed tests
dotnet test --filter "Category=Distributed" Source\Titan.Tests\Titan.Tests.csproj

What they cover:

  • Silo failover and grain reactivation
  • Cross-silo grain communication
  • High concurrency grain distribution
  • Parallel trades across silos

Database Tests

Tests that require YugabyteDB persistence:

# Run only database-specific tests
dotnet test --filter "Category=Database" Source\Titan.Tests\Titan.Tests.csproj

What they cover:

  • State persistence across silo restarts
  • Trade resumption after silo failure
  • Full cluster restart with data retention

Test Modes

In-Memory Mode

Uses Orleans MemoryGrainStorage. Fast and requires no external dependencies.

  • Use Case: Rapid local development, logic verification
  • Behavior: Database-specific tests are skipped. Grain state is not persisted.

Database Persistence Mode

Uses YugabyteDB via ADO.NET storage. Verifies real persistence behavior.

  • Use Case: CI/CD, verifying persistence, concurrency testing
  • Behavior: Full test suite runs including persistence validation

Test Files

FileDescriptionSilos
TradingFlowTests.csCore trading workflows1
TradeExpirationTests.csTrade auto-expiration1
TradeStreamTests.csOrleans Streams event publishing1
TradeBatchTests.csBatch add/remove and trade limits1
ItemTypeRegistryTests.csItem type registry CRUD1
DatabasePersistenceTests.csPersistence across restarts1
SocialGraphTests.csSocial relationships1
ItemHistoryTests.csItem audit trail1
DistributedClusterTests.csMulti-silo distributed tests2

Environment Setup

We provide automation scripts to set up the test environment.

Start Database

Use docker-up.ps1 to start YugabyteDB:

.\scripts\docker-up.ps1

This script automatically:

  1. Starts the Docker container
  2. Waits for the database to be ready
  3. Creates the titan database
  4. Applies the Orleans ADO.NET schema

Reset Database

To wipe all data and start fresh:

.\scripts\docker-reset.ps1

Continuous Integration

In CI environments (e.g., GitHub Actions), the workflow automatically:

  1. Starts YugabyteDB as a service container
  2. Initializes the schema
  3. Runs all tests with USE_DATABASE=true
env:
USE_DATABASE: "true"
YUGABYTE_CONNECTION: "Host=localhost;Port=5433;Database=titan;Username=yugabyte;Password=yugabyte"