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

Function TestVFSFile_NewDatabase_WriteAndSync

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

Source from the content-addressed store, hash-verified

778}
779
780func TestVFSFile_NewDatabase_WriteAndSync(t *testing.T) {
781 // Test writing to a new database and syncing to remote
782 client := newWriteTestReplicaClient()
783
784 tmpDir := t.TempDir()
785 bufferPath := tmpDir + "/.litestream-write-buffer"
786
787 logger := slog.Default()
788 f := NewVFSFile(client, "new.db", logger)
789 f.writeEnabled = true
790 f.dirty = make(map[uint32]int64)
791 f.syncInterval = 0
792 f.bufferPath = bufferPath
793
794 if err := f.Open(); err != nil {
795 t.Fatal(err)
796 }
797 defer f.Close()
798
799 // Write data to page 1
800 writeData := []byte("new database content")
801 n, err := f.WriteAt(writeData, 0)
802 if err != nil {
803 t.Fatal(err)
804 }
805 if n != len(writeData) {
806 t.Errorf("expected %d bytes written, got %d", len(writeData), n)
807 }
808
809 // Verify dirty page exists
810 if len(f.dirty) != 1 {
811 t.Errorf("expected 1 dirty page, got %d", len(f.dirty))
812 }
813
814 // Sync to remote
815 if err := f.Sync(0); err != nil {
816 t.Fatal(err)
817 }
818
819 // Verify TXID advanced
820 if f.expectedTXID != 1 {
821 t.Errorf("expected expectedTXID 1 after sync, got %d", f.expectedTXID)
822 }
823 if f.pendingTXID != 2 {
824 t.Errorf("expected pendingTXID 2 after sync, got %d", f.pendingTXID)
825 }
826
827 // Verify LTX file was written
828 client.mu.Lock()
829 if len(client.ltxFiles[0]) != 1 {
830 t.Errorf("expected 1 LTX file after sync, got %d", len(client.ltxFiles[0]))
831 }
832 if len(client.ltxFiles[0]) > 0 {
833 info := client.ltxFiles[0][0]
834 if info.MinTXID != 1 || info.MaxTXID != 1 {
835 t.Errorf("expected TXID 1, got min=%d max=%d", info.MinTXID, info.MaxTXID)
836 }
837 }

Callers

nothing calls this directly

Calls 8

OpenMethod · 0.95
CloseMethod · 0.95
WriteAtMethod · 0.95
SyncMethod · 0.95
NewVFSFileFunction · 0.85
LockMethod · 0.45
UnlockMethod · 0.45

Tested by

no test coverage detected