Skip to content

Commit 19c722b

Browse files
authored
Implement Position-Keeping E2E Test Suite (#715)
* feat: Implement comprehensive E2E test suite for position-keeping service Implements all 6 test cases covering critical paths: 1. TestPositionAggregation_E2E - Verifies correct summing by account + instrument + bucket 2. TestSoftDeletion_E2E - Verifies soft-deleted positions excluded from aggregations 3. TestAppendOnly_E2E - Documents append-only pattern (application-layer enforcement) 4. TestHighFrequencyInserts_E2E - Verifies >1000 inserts/sec without deadlock (2000 concurrent) 5. TestBucketIsolation_E2E - Verifies bucket isolation (PEAK/OFF_PEAK/SHOULDER separate) 6. TestMultiTenantIsolation_E2E - Verifies schema-based tenant isolation 7. TestPerformanceBaselines_E2E - Performance benchmarks (<100ms aggregation, >1000/sec throughput) Key implementation details: - Uses CockroachDB testcontainers for production parity (not PostgreSQL) - Uses shared/platform/await for async operations (not time.Sleep) - Schema-qualified table names for thread-safe concurrent operations - Append-only enforcement documented for application layer (CockroachDB has limited trigger support) - All tests pass with performance exceeding baselines Test coverage: >80% of critical position-keeping paths Performance: Aggregation 5-11ms for 1000 positions, throughput 2600-5100 inserts/sec * fix: Make insertPosition helper goroutine-safe Changes: - Changed insertPosition signature to return (uuid.UUID, error) - Replaced require.True/require.NoError with error returns - Use sqlDB.ExecContext(ctx) to respect context timeouts - Updated all 27 call sites to handle returned errors properly - Added error channels to concurrent test goroutines - Fixed variable shadowing issues with err declarations Addresses CodeRabbit feedback about goroutine safety: - Helper now safe for concurrent use in goroutines - Context timeouts properly honored in SQL operations - Errors propagated instead of panicking test failures * fix: Release context resources immediately in loop Move cancel() call from defer to immediate execution after insertPosition completes to prevent context accumulation in the goroutine loop. Addresses CodeRabbit feedback: defer cancel() inside loop caused all 20 contexts per worker to remain active until goroutine exit. Now each context is released immediately after use. --------- Co-authored-by: Ben Coombs <bjcoombs@users.noreply.github.com>
1 parent ca1b334 commit 19c722b

1 file changed

Lines changed: 791 additions & 0 deletions

File tree

0 commit comments

Comments
 (0)