test(vt): cover partial history chunk capacity
- commit
- 2c3eaa1deadfcabd5149cda391974ff504528299
- author
- brice · · 2026-07-12 15:07 UTC
- parent
- adf2142
- signature
- GPG Verified
CD88F9E564E0102646FB6077A1A07C7C7C3E349D· arch-gpg Verified for the committer email
1 file · +26 -10
M pkg/vt/history_test.go +26 -10
| @@ -8,30 +8,46 @@ import ( | |||
| 8 | 8 | ||
| 9 | 9 | func TestHistoryOrdersSealedChunksAndEvictsAtCapacity(t *testing.T) { | |
| 10 | 10 | tests := []struct { | |
| 11 | - | name string | |
| 12 | - | rows []string | |
| 13 | - | want []string | |
| 11 | + | name string | |
| 12 | + | maxRows int | |
| 13 | + | chunkRows int | |
| 14 | + | rows []string | |
| 15 | + | want []string | |
| 14 | 16 | }{ | |
| 15 | 17 | { | |
| 16 | - | name: "oldest chunks are evicted before newer chunks", | |
| 17 | - | rows: []string{"aaaa", "bbbb", "cccc", "dddd", "eeee", "ffff"}, | |
| 18 | - | want: []string{"cccc", "dddd", "eeee", "ffff"}, | |
| 18 | + | name: "oldest chunks are evicted before newer chunks", | |
| 19 | + | maxRows: 4, | |
| 20 | + | chunkRows: 2, | |
| 21 | + | rows: []string{"aaaa", "bbbb", "cccc", "dddd", "eeee", "ffff"}, | |
| 22 | + | want: []string{"cccc", "dddd", "eeee", "ffff"}, | |
| 23 | + | }, | |
| 24 | + | { | |
| 25 | + | name: "nonmultiple capacity evicts a whole oldest immutable chunk", | |
| 26 | + | maxRows: 5, | |
| 27 | + | chunkRows: 2, | |
| 28 | + | rows: []string{"0000", "1111", "2222", "3333", "4444", "5555"}, | |
| 29 | + | want: []string{"2222", "3333", "4444", "5555"}, | |
| 19 | 30 | }, | |
| 20 | 31 | { | |
| 21 | - | name: "rows preserve append order across chunk boundaries", | |
| 22 | - | rows: []string{"0000", "1111", "2222", "3333"}, | |
| 23 | - | want: []string{"0000", "1111", "2222", "3333"}, | |
| 32 | + | name: "rows preserve append order across chunk boundaries", | |
| 33 | + | maxRows: 4, | |
| 34 | + | chunkRows: 2, | |
| 35 | + | rows: []string{"0000", "1111", "2222", "3333"}, | |
| 36 | + | want: []string{"0000", "1111", "2222", "3333"}, | |
| 24 | 37 | }, | |
| 25 | 38 | } | |
| 26 | 39 | ||
| 27 | 40 | for _, tt := range tests { | |
| 28 | 41 | t.Run(tt.name, func(t *testing.T) { | |
| 29 | - | history := NewHistory(HistoryConfig{MaxRows: 4, ChunkRows: 2}) | |
| 42 | + | history := NewHistory(HistoryConfig{MaxRows: tt.maxRows, ChunkRows: tt.chunkRows}) | |
| 30 | 43 | for _, text := range tt.rows { | |
| 31 | 44 | history.Append(historyRow(text)) | |
| 32 | 45 | } | |
| 33 | 46 | ||
| 34 | 47 | view := history.View() | |
| 48 | + | if got := view.Len(); got > tt.maxRows { | |
| 49 | + | t.Fatalf("retained row count = %d, exceeds capacity %d", got, tt.maxRows) | |
| 50 | + | } | |
| 35 | 51 | if got := historyViewTexts(view); !equalStrings(got, tt.want) { | |
| 36 | 52 | t.Fatalf("view rows = %#v, want %#v", got, tt.want) | |
| 37 | 53 | } | |
| @@ -8,30 +8,46 @@ import ( | |||||
| 8 | 8 | ||||
| 9 | func TestHistoryOrdersSealedChunksAndEvictsAtCapacity(t *testing.T) { | 9 | func TestHistoryOrdersSealedChunksAndEvictsAtCapacity(t *testing.T) { | ||
| 10 | tests := []struct { | 10 | tests := []struct { | ||
| 11 | - | name string | 11 | + | name string |
| 12 | - | rows []string | 12 | + | maxRows int |
| 13 | - | want []string | 13 | + | chunkRows int |
| 14 | + | rows []string | |||
| 15 | + | want []string | |||
| 14 | }{ | 16 | }{ | ||
| 15 | { | 17 | { | ||
| 16 | - | name: "oldest chunks are evicted before newer chunks", | 18 | + | name: "oldest chunks are evicted before newer chunks", |
| 17 | - | rows: []string{"aaaa", "bbbb", "cccc", "dddd", "eeee", "ffff"}, | 19 | + | maxRows: 4, |
| 18 | - | want: []string{"cccc", "dddd", "eeee", "ffff"}, | 20 | + | chunkRows: 2, |
| 21 | + | rows: []string{"aaaa", "bbbb", "cccc", "dddd", "eeee", "ffff"}, | |||
| 22 | + | want: []string{"cccc", "dddd", "eeee", "ffff"}, | |||
| 23 | + | }, | |||
| 24 | + | { | |||
| 25 | + | name: "nonmultiple capacity evicts a whole oldest immutable chunk", | |||
| 26 | + | maxRows: 5, | |||
| 27 | + | chunkRows: 2, | |||
| 28 | + | rows: []string{"0000", "1111", "2222", "3333", "4444", "5555"}, | |||
| 29 | + | want: []string{"2222", "3333", "4444", "5555"}, | |||
| 19 | }, | 30 | }, | ||
| 20 | { | 31 | { | ||
| 21 | - | name: "rows preserve append order across chunk boundaries", | 32 | + | name: "rows preserve append order across chunk boundaries", |
| 22 | - | rows: []string{"0000", "1111", "2222", "3333"}, | 33 | + | maxRows: 4, |
| 23 | - | want: []string{"0000", "1111", "2222", "3333"}, | 34 | + | chunkRows: 2, |
| 35 | + | rows: []string{"0000", "1111", "2222", "3333"}, | |||
| 36 | + | want: []string{"0000", "1111", "2222", "3333"}, | |||
| 24 | }, | 37 | }, | ||
| 25 | } | 38 | } | ||
| 26 | 39 | ||||
| 27 | for _, tt := range tests { | 40 | for _, tt := range tests { | ||
| 28 | t.Run(tt.name, func(t *testing.T) { | 41 | t.Run(tt.name, func(t *testing.T) { | ||
| 29 | - | history := NewHistory(HistoryConfig{MaxRows: 4, ChunkRows: 2}) | 42 | + | history := NewHistory(HistoryConfig{MaxRows: tt.maxRows, ChunkRows: tt.chunkRows}) |
| 30 | for _, text := range tt.rows { | 43 | for _, text := range tt.rows { | ||
| 31 | history.Append(historyRow(text)) | 44 | history.Append(historyRow(text)) | ||
| 32 | } | 45 | } | ||
| 33 | 46 | ||||
| 34 | view := history.View() | 47 | view := history.View() | ||
| 48 | + | if got := view.Len(); got > tt.maxRows { | |||
| 49 | + | t.Fatalf("retained row count = %d, exceeds capacity %d", got, tt.maxRows) | |||
| 50 | + | } | |||
| 35 | if got := historyViewTexts(view); !equalStrings(got, tt.want) { | 51 | if got := historyViewTexts(view); !equalStrings(got, tt.want) { | ||
| 36 | t.Fatalf("view rows = %#v, want %#v", got, tt.want) | 52 | t.Fatalf("view rows = %#v, want %#v", got, tt.want) | ||
| 37 | } | 53 | } | ||