mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-03-30 15:08:33 +00:00

* [DEV-81] Overwrite maxOpenFiles for testInterface to force tests to check the LRU-mechanism in openFile * [DEV-81] Added database.UseLogger test * [DEV-81] Completed coverage of reconcileDB() * [DEV-81] Added some tests for dbcache * [DEV-81] Moved init and UseLogger to separate file to make them more easily-testable + added tests * [DEV-81] Added tests for deleteFile * [DEV-81] Added tests to cursor.Delete + made sure it returns error when transaction is not writable * [DEV-81] Moved database/error_test.go from database_test package to database package + added test for IsErrorCode * [DEV-81] Added tests for handleRollback error-cases * [DEV-81] Added tests for cursor.skipPendingUpdates * [DEV-81] Added tests for various cursor edge-cases * [DEV-81] tx.putKey no longer returns error, because there is no case when it does * [DEV-81] Added tests to CreateBucket error cases * [DEV-81] Added tests to bucket.Get and .Delete error cases + .Delete now returns error on empty key * [DEV-81] Added test for ForEachBucket * [DEV-81] Added tests to StoreBlock * [DEV-81] Added test for deleting a double nested bucket * [DEV-81] Removed log_test, as it is no longer necessary with the logging system re-design * [DEV-81] Added test to some of writePendingAndCommit error-cases * [DEV-81] Update references from btcutil to btcd/util * [DEV-81] Add tests for dbCacheIterator{.Next(), .Prev(), .Key, .Value()} in cases when iterator is exhausted * [DEV-81] Added tests for ldbIterator placeholder functions * [DEV-81] Added test name to Error messsages in TestSkipPendingUpdates * [DEV-81] Begin writing TestSkipPendingUpdatesCache * [DEV-81] Added error-cases for DBCache.flush() and DBCache.commitTreaps() * [DEV-81] Use monkey.patch from bou.ke and not from github * [DEV-81] Rewrote IsErrorCode in both database and txscript packages to be more concise * [DEV-81] Rename any database.Tx to dbTx instead of tx - to remove confusion with coin Tx * [DEV-81] Fix typo * [DEV-81] Use os.TempDir() instead of /tmp/ to be cross-platform * [DEV-81] use SimNet for database tests + Error if testDB exists after deleting it * [DEV-81] Removed useLogger - it's redundant * [DEV-81] Added comment on how CRC32 checksums are calculated in reconcile_test.go * [DEV-81] Added comment that explains what setWriteRow does * [DEV-81] Use constant instead of hard-coded value * [DEV-81] Fixed some typo's + better formatting
98 lines
2.2 KiB
Go
98 lines
2.2 KiB
Go
// Copyright (c) 2015-2016 The btcsuite developers
|
|
// Use of this source code is governed by an ISC
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package ffldb
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/daglabs/btcd/dagconfig"
|
|
"github.com/daglabs/btcd/database"
|
|
"github.com/daglabs/btcd/util"
|
|
)
|
|
|
|
// BenchmarkBlockHeader benchmarks how long it takes to load the mainnet genesis
|
|
// block header.
|
|
func BenchmarkBlockHeader(b *testing.B) {
|
|
// Start by creating a new database and populating it with the mainnet
|
|
// genesis block.
|
|
dbPath := filepath.Join(os.TempDir(), "ffldb-benchblkhdr")
|
|
_ = os.RemoveAll(dbPath)
|
|
db, err := database.Create("ffldb", dbPath, blockDataNet)
|
|
if err != nil {
|
|
b.Fatal(err)
|
|
}
|
|
defer os.RemoveAll(dbPath)
|
|
defer db.Close()
|
|
err = db.Update(func(dbTx database.Tx) error {
|
|
block := util.NewBlock(dagconfig.MainNetParams.GenesisBlock)
|
|
return dbTx.StoreBlock(block)
|
|
})
|
|
if err != nil {
|
|
b.Fatal(err)
|
|
}
|
|
|
|
b.ReportAllocs()
|
|
b.ResetTimer()
|
|
err = db.View(func(dbTx database.Tx) error {
|
|
blockHash := dagconfig.MainNetParams.GenesisHash
|
|
for i := 0; i < b.N; i++ {
|
|
_, err := dbTx.FetchBlockHeader(blockHash)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
}
|
|
return nil
|
|
})
|
|
if err != nil {
|
|
b.Fatal(err)
|
|
}
|
|
|
|
// Don't benchmark teardown.
|
|
b.StopTimer()
|
|
}
|
|
|
|
// BenchmarkBlockHeader benchmarks how long it takes to load the mainnet genesis
|
|
// block.
|
|
func BenchmarkBlock(b *testing.B) {
|
|
// Start by creating a new database and populating it with the mainnet
|
|
// genesis block.
|
|
dbPath := filepath.Join(os.TempDir(), "ffldb-benchblk")
|
|
_ = os.RemoveAll(dbPath)
|
|
db, err := database.Create("ffldb", dbPath, blockDataNet)
|
|
if err != nil {
|
|
b.Fatal(err)
|
|
}
|
|
defer os.RemoveAll(dbPath)
|
|
defer db.Close()
|
|
err = db.Update(func(dbTx database.Tx) error {
|
|
block := util.NewBlock(dagconfig.MainNetParams.GenesisBlock)
|
|
return dbTx.StoreBlock(block)
|
|
})
|
|
if err != nil {
|
|
b.Fatal(err)
|
|
}
|
|
|
|
b.ReportAllocs()
|
|
b.ResetTimer()
|
|
err = db.View(func(dbTx database.Tx) error {
|
|
blockHash := dagconfig.MainNetParams.GenesisHash
|
|
for i := 0; i < b.N; i++ {
|
|
_, err := dbTx.FetchBlock(blockHash)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
}
|
|
return nil
|
|
})
|
|
if err != nil {
|
|
b.Fatal(err)
|
|
}
|
|
|
|
// Don't benchmark teardown.
|
|
b.StopTimer()
|
|
}
|