Commit Graph

1 Commits

Author SHA1 Message Date
chrislu
f69e2a0c2d feat: Add unit tests to reproduce buffer flush offset gaps
Phase 7: Unit Test Creation

Created comprehensive unit tests in log_buffer_flush_gap_test.go:
  - TestFlushOffsetGap_ReproduceDataLoss: Tests for gaps between disk and memory
  - TestFlushOffsetGap_CheckPrevBuffers: Tests if data stuck in prevBuffers
  - TestFlushOffsetGap_ConcurrentWriteAndFlush: Tests race conditions
  - TestFlushOffsetGap_ForceFlushAdvancesBuffer: Tests offset advancement

Initial Findings:
  - Tests run but don't reproduce exact production scenario
  - Reason: AddToBuffer doesn't auto-assign offsets (stays at 0)
  - In production: messages come with pre-assigned offsets from MQ broker
  - Need to use AddLogEntryToBuffer with explicit offsets instead

Test Structure:
  - Flush callback captures minOffset, maxOffset, buffer contents
  - Parse flushed buffers to extract actual messages
  - Compare flushed offsets vs in-memory offsets
  - Detect gaps, overlaps, and missing data

Next: Enhance tests to use explicit offset assignment to match production scenario
2025-10-17 12:48:12 -07:00