MCPcopy
hub / github.com/benbjohnson/litestream / TestVFSFile_WriteBufferClearAfterSync

Function TestVFSFile_WriteBufferClearAfterSync

vfs_write_test.go:602–648  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

600}
601
602func TestVFSFile_WriteBufferClearAfterSync(t *testing.T) {
603 client := newWriteTestReplicaClient()
604
605 // Create initial LTX file
606 pageSize := uint32(4096)
607 initialPage := make([]byte, pageSize)
608 createTestLTXFile(t, client, 1, pageSize, 1, map[uint32][]byte{1: initialPage})
609
610 // Create temp directory for buffer
611 tmpDir := t.TempDir()
612 bufferPath := tmpDir + "/.litestream-write-buffer"
613
614 // Create VFSFile with write buffer
615 logger := slog.Default()
616 f := NewVFSFile(client, "test.db", logger)
617 f.writeEnabled = true
618 f.dirty = make(map[uint32]int64)
619 f.syncInterval = 0
620 f.bufferPath = bufferPath
621
622 if err := f.Open(); err != nil {
623 t.Fatal(err)
624 }
625 defer f.Close()
626
627 // Write data
628 if _, err := f.WriteAt([]byte("sync test"), 0); err != nil {
629 t.Fatal(err)
630 }
631
632 // Check buffer has content before sync
633 stat, _ := os.Stat(bufferPath)
634 if stat.Size() == 0 {
635 t.Error("buffer should have content before sync")
636 }
637
638 // Sync to remote
639 if err := f.Sync(0); err != nil {
640 t.Fatal(err)
641 }
642
643 // Check buffer is cleared after sync
644 stat, _ = os.Stat(bufferPath)
645 if stat.Size() != 0 {
646 t.Errorf("buffer should be empty after sync, got size %d", stat.Size())
647 }
648}
649
650func TestVFSFile_OpenFailsWithInvalidBufferPath(t *testing.T) {
651 client := newWriteTestReplicaClient()

Callers

nothing calls this directly

Calls 8

OpenMethod · 0.95
CloseMethod · 0.95
WriteAtMethod · 0.95
SyncMethod · 0.95
NewVFSFileFunction · 0.85
createTestLTXFileFunction · 0.70
ErrorMethod · 0.45

Tested by

no test coverage detected