lib/mergeset: add a test for too long item passed to Table.AddItems()

This commit is contained in:
Aliaksandr Valialkin 2024-02-08 14:12:37 +02:00
parent 5817e4c0c1
commit 0f5176380b
No known key found for this signature in database
GPG Key ID: 52C003EE2BCDB9EB
2 changed files with 22 additions and 0 deletions

View File

@ -244,6 +244,7 @@ func (ris *rawItemsShard) addItems(tb *Table, items [][]byte) [][]byte {
ibs = append(ibs, ib)
continue
}
ris.mu.Unlock()
logger.Panicf("BUG: cannot insert too big item into an empty inmemoryBlock; len(item)=%d; the caller should be responsible for avoiding too big items", len(item))
}
ris.ibs = ibs

View File

@ -33,6 +33,27 @@ func TestTableOpenClose(t *testing.T) {
}
}
func TestTableAddItemsTooLongItem(t *testing.T) {
const path = "TestTableAddItemsTooLongItem"
if err := os.RemoveAll(path); err != nil {
t.Fatalf("cannot remove %q: %s", path, err)
}
var isReadOnly uint32
tb := MustOpenTable(path, nil, nil, &isReadOnly)
func() {
defer func() {
if r := recover(); r == nil {
t.Fatalf("expecting panic")
}
}()
tb.AddItems([][]byte{make([]byte, maxInmemoryBlockSize+1)})
}()
t.Logf("foobar")
tb.MustClose()
_ = os.RemoveAll(path)
}
func TestTableAddItemsSerial(t *testing.T) {
r := rand.New(rand.NewSource(1))
const path = "TestTableAddItemsSerial"