dbtest
v1.21.5
Documentation
pkg.go.dev ↗Constants
KiB (2 declarations)
const ( KiB = 1024 MiB = 1024 * KiB )
Variables
Benchmarks (2 declarations)
var (
// Benchmarks is a list of all database benchmarks
Benchmarks = map[string]func(b *testing.B, db database.Database, keys, values [][]byte){
"Get": BenchmarkGet,
"Put": BenchmarkPut,
"Delete": BenchmarkDelete,
"BatchPut": BenchmarkBatchPut,
"BatchDelete": BenchmarkBatchDelete,
"BatchWrite": BenchmarkBatchWrite,
"ParallelGet": BenchmarkParallelGet,
"ParallelPut": BenchmarkParallelPut,
"ParallelDelete": BenchmarkParallelDelete,
}
// BenchmarkSizes to use with each benchmark
BenchmarkSizes = [][]int{
{1024, 32, 32},
{1024, 256, 256},
{1024, 2 * KiB, 2 * KiB},
}
)
ErrNotFound (2 declarations)
var ( // Import errors from db package ErrNotFound = db.ErrNotFound ErrClosed = db.ErrClosed )
Tests
var Tests = map[string]func(t *testing.T, db db.Database){
"SimpleKeyValueClosed": TestSimpleKeyValueClosed,
"NewBatchClosed": TestNewBatchClosed,
"BatchPut": TestBatchPut,
"BatchDelete": TestBatchDelete,
"BatchReset": TestBatchReset,
"BatchReuse": TestBatchReuse,
"BatchRewrite": TestBatchRewrite,
"BatchReplay": TestBatchReplay,
"BatchReplayPropagateError": TestBatchReplayPropagateError,
"BatchInner": TestBatchInner,
"BatchLargeSize": TestBatchLargeSize,
"IteratorSnapshot": TestIteratorSnapshot,
"Iterator": TestIterator,
"IteratorStart": TestIteratorStart,
"IteratorPrefix": TestIteratorPrefix,
"IteratorStartPrefix": TestIteratorStartPrefix,
"IteratorMemorySafety": TestIteratorMemorySafety,
"IteratorClosed": TestIteratorClosed,
"IteratorError": TestIteratorError,
"IteratorErrorAfterRelease": TestIteratorErrorAfterRelease,
"CompactNoPanic": TestCompactNoPanic,
"MemorySafetyBatch": TestMemorySafetyBatch,
"ModifyValueAfterBatchPut": TestModifyValueAfterBatchPut,
"ModifyValueAfterBatchPutReplay": TestModifyValueAfterBatchPutReplay,
"ConcurrentBatches": TestConcurrentBatches,
"ManySmallConcurrentKVPairBatches": TestManySmallConcurrentKVPairBatches,
}
Tests is a list of all database tests
TestsBasic
var TestsBasic = map[string]func(t *testing.T, db db.KeyValueReaderWriterDeleter){
"SimpleKeyValue": TestSimpleKeyValue,
"OverwriteKeyValue": TestOverwriteKeyValue,
"EmptyKey": TestEmptyKey,
"KeyEmptyValue": TestKeyEmptyValue,
"MemorySafetyDatabase": TestMemorySafetyDatabase,
"ModifyValueAfterPut": TestModifyValueAfterPut,
"PutGetEmpty": TestPutGetEmpty,
}
TestsBasic is a list of all basic database tests that require only a KeyValueReaderWriterDeleter.
Functions
BenchDatabaseSuite
func BenchDatabaseSuite(b *testing.B, New func() ethdb.KeyValueStore)
BenchDatabaseSuite runs a suite of benchmarks against a KeyValueStore database implementation.
BenchmarkBatchDelete
func BenchmarkBatchDelete(b *testing.B, db database.Database, keys, _ [][]byte)
BenchmarkBatchDelete measures the time it takes to batch delete.
BenchmarkBatchPut
func BenchmarkBatchPut(b *testing.B, db database.Database, keys, values [][]byte)
BenchmarkBatchPut measures the time it takes to batch put.
BenchmarkBatchWrite
func BenchmarkBatchWrite(b *testing.B, db database.Database, keys, values [][]byte)
BenchmarkBatchWrite measures the time it takes to batch write.
BenchmarkDelete
func BenchmarkDelete(b *testing.B, db database.Database, keys, values [][]byte)
BenchmarkDelete measures the time it takes to delete a (k, v) from a database.
BenchmarkGet
func BenchmarkGet(b *testing.B, db database.Database, keys, values [][]byte)
BenchmarkGet measures the time it takes to get an operation from a database.
BenchmarkParallelDelete
func BenchmarkParallelDelete(b *testing.B, db database.Database, keys, values [][]byte)
BenchmarkParallelDelete measures the time it takes to delete a (k, v) from the database.
BenchmarkParallelGet
func BenchmarkParallelGet(b *testing.B, db database.Database, keys, values [][]byte)
BenchmarkParallelGet measures the time it takes to read in parallel.
BenchmarkParallelPut
func BenchmarkParallelPut(b *testing.B, db database.Database, keys, values [][]byte)
BenchmarkParallelPut measures the time it takes to write to the db in parallel.
BenchmarkPut
func BenchmarkPut(b *testing.B, db database.Database, keys, values [][]byte)
BenchmarkPut measures the time it takes to write an operation to a database.
FuzzKeyValue
func FuzzKeyValue(f *testing.F, db db.KeyValueReaderWriterDeleter)
FuzzNewIteratorWithPrefix
func FuzzNewIteratorWithPrefix(f *testing.F, db db.Database)
FuzzNewIteratorWithStartAndPrefix
func FuzzNewIteratorWithStartAndPrefix(f *testing.F, db db.Database)
SetupBenchmark
func SetupBenchmark(b *testing.B, count int, keySize, valueSize int) ([][]byte, [][]byte)
Writes size data into the db in order to setup reads in subsequent tests.
TestBatchDelete
func TestBatchDelete(t *testing.T, db db.Database)
TestBatchDelete tests to make sure that batched deletes work as expected.
TestBatchInner
func TestBatchInner(t *testing.T, db db.Database)
TestBatchInner tests to make sure that inner can be used to write to the database.
TestBatchLargeSize
func TestBatchLargeSize(t *testing.T, db db.Database)
TestBatchLargeSize tests to make sure that the batch can support a large amount of entries.
TestBatchPut
func TestBatchPut(t *testing.T, db db.Database)
TestBatchPut tests to make sure that batched writes work as expected.
TestBatchReplay
func TestBatchReplay(t *testing.T, db db.Database)
TestBatchReplay tests to make sure that batches will correctly replay their contents.
TestBatchReplayPropagateError
func TestBatchReplayPropagateError(t *testing.T, db db.Database)
TestBatchReplayPropagateError tests to make sure that batches will correctly propagate any returned error during Replay.
TestBatchReset
func TestBatchReset(t *testing.T, db db.Database)
TestBatchReset tests to make sure that a batch drops un-written operations when it is reset.
TestBatchReuse
func TestBatchReuse(t *testing.T, db db.Database)
TestBatchReuse tests to make sure that a batch can be reused once it is reset.
TestBatchRewrite
func TestBatchRewrite(t *testing.T, db db.Database)
TestBatchRewrite tests to make sure that write can be called multiple times on a batch and the values will be updated correctly.
TestCompactNoPanic
func TestCompactNoPanic(t *testing.T, db db.Database)
TestCompactNoPanic tests to make sure compact never panics.
TestConcurrentBatches
func TestConcurrentBatches(t *testing.T, db db.Database)
TestDatabaseSuite
func TestDatabaseSuite(t *testing.T, New func() ethdb.KeyValueStore)
TestDatabaseSuite runs a suite of tests against a KeyValueStore database implementation.
TestEmptyKey
func TestEmptyKey(t *testing.T, db db.KeyValueReaderWriterDeleter)
TestIterator
func TestIterator(t *testing.T, db db.Database)
TestIterator tests to make sure the database iterates over the database contents lexicographically.
TestIteratorClosed
func TestIteratorClosed(t *testing.T, db db.Database)
TestIteratorClosed tests to make sure that an iterator that was created with a closed database will report a closed error correctly.
TestIteratorError
func TestIteratorError(t *testing.T, db db.Database)
TestIteratorError tests to make sure that an iterator on a database will report itself as being exhausted and return ErrClosed to indicate that the iteration was not successful. Additionally tests that an iterator that has already called Next() can still serve its current value after the underlying DB was closed.
TestIteratorErrorAfterRelease
func TestIteratorErrorAfterRelease(t *testing.T, db db.Database)
TestIteratorErrorAfterRelease tests to make sure that an iterator that was released still reports the error correctly.
TestIteratorMemorySafety
func TestIteratorMemorySafety(t *testing.T, db db.Database)
TestIteratorMemorySafety tests to make sure that keys can values are able to be modified from the returned iterator.
TestIteratorPrefix
func TestIteratorPrefix(t *testing.T, db db.Database)
TestIteratorPrefix tests to make sure the iterator can be configured to skip keys missing the provided prefix.
TestIteratorSnapshot
func TestIteratorSnapshot(t *testing.T, db db.Database)
TestIteratorSnapshot tests to make sure the database iterates over a snapshot of the database at the time of the iterator creation.
TestIteratorStart
func TestIteratorStart(t *testing.T, db db.Database)
TestIteratorStart tests to make sure the iterator can be configured to start mid way through the database.
TestIteratorStartPrefix
func TestIteratorStartPrefix(t *testing.T, db db.Database)
TestIteratorStartPrefix tests to make sure that the iterator can start mid way through the database while skipping a prefix.
TestKeyEmptyValue
func TestKeyEmptyValue(t *testing.T, db db.KeyValueReaderWriterDeleter)
TestManySmallConcurrentKVPairBatches
func TestManySmallConcurrentKVPairBatches(t *testing.T, db db.Database)
TestMemorySafetyBatch
func TestMemorySafetyBatch(t *testing.T, db db.Database)
TestMemorySafetyBatch ensures it is safe to modify a key after passing it to Batch.Put.
TestMemorySafetyDatabase
func TestMemorySafetyDatabase(t *testing.T, db db.KeyValueReaderWriterDeleter)
TestMemorySafetyDatabase ensures it is safe to modify a key after passing it to Database.Put and Database.Get.
TestModifyValueAfterBatchPut
func TestModifyValueAfterBatchPut(t *testing.T, db db.Database)
TestModifyValueAfterBatchPutReplay
func TestModifyValueAfterBatchPutReplay(t *testing.T, db db.Database)
TestModifyValueAfterPut
func TestModifyValueAfterPut(t *testing.T, db db.KeyValueReaderWriterDeleter)
TestNewBatchClosed
func TestNewBatchClosed(t *testing.T, db db.Database)
TestNewBatchClosed tests to make sure that calling NewBatch on a closed database returns a batch that errors correctly.
TestOverwriteKeyValue
func TestOverwriteKeyValue(t *testing.T, db db.KeyValueReaderWriterDeleter)
TestPutGetEmpty
func TestPutGetEmpty(t *testing.T, db db.KeyValueReaderWriterDeleter)
TestSimpleKeyValue
func TestSimpleKeyValue(t *testing.T, db db.KeyValueReaderWriterDeleter)
TestSimpleKeyValue tests to make sure that simple Put + Get + Delete + Has calls return the expected values.
TestSimpleKeyValueClosed
func TestSimpleKeyValueClosed(t *testing.T, db db.Database)
TestSimpleKeyValueClosed tests to make sure that Put + Get + Delete + Has calls return the correct error when the database has been closed.