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=truefor 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
| File | Description | Silos |
|---|---|---|
TradingFlowTests.cs | Core trading workflows | 1 |
TradeExpirationTests.cs | Trade auto-expiration | 1 |
TradeStreamTests.cs | Orleans Streams event publishing | 1 |
TradeBatchTests.cs | Batch add/remove and trade limits | 1 |
ItemTypeRegistryTests.cs | Item type registry CRUD | 1 |
DatabasePersistenceTests.cs | Persistence across restarts | 1 |
SocialGraphTests.cs | Social relationships | 1 |
ItemHistoryTests.cs | Item audit trail | 1 |
DistributedClusterTests.cs | Multi-silo distributed tests | 2 |
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:
- Starts the Docker container
- Waits for the database to be ready
- Creates the
titandatabase - 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:
- Starts YugabyteDB as a service container
- Initializes the schema
- Runs all tests with
USE_DATABASE=true
env:
USE_DATABASE: "true"
YUGABYTE_CONNECTION: "Host=localhost;Port=5433;Database=titan;Username=yugabyte;Password=yugabyte"