Skip to content

Implement Comprehensive Event Sourcing Test Infrastructure #145

@jwilger

Description

@jwilger

Priority: 🟡 HIGH

Problem

Missing critical testing infrastructure for event-sourced systems including temporal logic testing, projection testing, and event fixture generation.

Expert Analysis (Michael Feathers - Event Sourcing Test Architect)

Critical gaps identified:

  • No temporal logic testing for event ordering
  • Limited projection testing infrastructure
  • Missing concurrent event handling tests
  • No saga/process manager tests
  • Insufficient event store integration tests
  • Missing characterization tests
  • No event versioning tests

Required Implementation

1. Event Fixture Generation Framework

pub struct EventStreamBuilder {
    events: Vec<DomainEvent>,
    clock: MockClock,
}

impl EventStreamBuilder {
    pub fn with_session_lifecycle(mut self, session_id: SessionId) -> Self {
        self.events.extend(vec![
            DomainEvent::SessionStarted {
                session_id: session_id.clone(),
                user_id: UserId::generate(),
                started_at: self.clock.now(),
            },
            // Add requests...
            DomainEvent::SessionEnded {
                session_id,
                ended_at: self.clock.advance_by(Duration::hours(1)),
            }
        ]);
        self
    }
}

2. Time-Travel Testing Harness

pub struct TimeTravelTestHarness {
    event_store: InMemoryEventStore,
    clock: Arc<MockClock>,
}

impl TimeTravelTestHarness {
    pub async fn replay_to(&self, target_time: Timestamp) -> State {
        let events = self.event_store
            .read_all_events_before(target_time)
            .await?;
            
        events.fold(State::default(), |mut state, event| {
            state.apply(&event.payload);
            state
        })
    }
}

3. Projection Rebuild Testing

#[tokio::test]
async fn test_projection_rebuild_consistency() {
    let event_store = InMemoryEventStore::new();
    // Generate complex event history
    
    // Rebuild projection from scratch
    let projection = rebuild_version_projection(&event_store).await;
    
    // Verify projection integrity
    assert_projection_invariants(&projection);
}

4. Concurrent Event Testing

#[tokio::test]
async fn test_concurrent_command_execution() {
    // Test optimistic concurrency control
    // Verify conflict resolution
}

Test Organization Structure

tests/
├── event_sourcing/
│   ├── fixtures/
│   │   ├── event_builders.rs
│   │   └── stream_builders.rs
│   ├── temporal/
│   │   ├── time_travel_tests.rs
│   │   └── event_ordering_tests.rs
│   ├── projections/
│   │   ├── rebuild_tests.rs
│   │   └── consistency_tests.rs
│   ├── concurrency/
│   │   └── optimistic_locking_tests.rs
│   └── integration/
│       └── postgres_tests.rs
├── property_tests/
│   └── event_invariants.rs
└── characterization/
    └── behavior_tests.rs

Success Criteria

  • Event fixture builder framework implemented
  • Time-travel testing capabilities added
  • Projection rebuild tests created
  • Concurrent event handling tested
  • Property-based tests for invariants
  • PostgreSQL integration tests working
  • Characterization tests capturing behavior

References

  • ADR-0005: Testing Strategy
  • EventCore testing best practices

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions