mirror of
https://github.com/tendermint/tendermint.git
synced 2026-01-07 13:55:17 +00:00
Clean up temp files more thoroughly after testing. (#7815)
Our test cases spew a lot of files and directories around $TMPDIR. Make more thorough use of the testing package's TempDir methods to ensure these are cleaned up. In a few cases, this required plumbing test contexts through existing helper code. In a couple places an explicit path was required, to work around cases where we do global setup during a TestMain function. Those cases probably deserve more thorough cleansing (preferably with fire), but for now I have just worked around it to keep focused on the cleanup.
This commit is contained in:
@@ -4,7 +4,6 @@ import (
|
||||
"context"
|
||||
"crypto/rand"
|
||||
"fmt"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
dbm "github.com/tendermint/tm-db"
|
||||
@@ -15,10 +14,7 @@ import (
|
||||
)
|
||||
|
||||
func BenchmarkTxSearch(b *testing.B) {
|
||||
dbDir, err := os.MkdirTemp("", "benchmark_tx_search_test")
|
||||
if err != nil {
|
||||
b.Errorf("failed to create temporary directory: %s", err)
|
||||
}
|
||||
dbDir := b.TempDir()
|
||||
|
||||
db, err := dbm.NewGoLevelDB("benchmark_tx_search_test", dbDir)
|
||||
if err != nil {
|
||||
|
||||
@@ -3,7 +3,6 @@ package kv
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/gogo/protobuf/proto"
|
||||
@@ -333,9 +332,7 @@ func txResultWithEvents(events []abci.Event) *abci.TxResult {
|
||||
}
|
||||
|
||||
func benchmarkTxIndex(txsCount int64, b *testing.B) {
|
||||
dir, err := os.MkdirTemp("", "tx_index_db")
|
||||
require.NoError(b, err)
|
||||
defer os.RemoveAll(dir)
|
||||
dir := b.TempDir()
|
||||
|
||||
store, err := dbm.NewDB("tx_index", "goleveldb", dir)
|
||||
require.NoError(b, err)
|
||||
|
||||
@@ -26,7 +26,7 @@ import (
|
||||
|
||||
// setupTestCase does setup common to all test cases.
|
||||
func setupTestCase(t *testing.T) (func(t *testing.T), dbm.DB, sm.State) {
|
||||
cfg, err := config.ResetTestRoot("state_")
|
||||
cfg, err := config.ResetTestRoot(t.TempDir(), "state_")
|
||||
require.NoError(t, err)
|
||||
|
||||
dbType := dbm.BackendType(cfg.DBBackend)
|
||||
|
||||
@@ -110,7 +110,7 @@ func TestStoreLoadValidators(t *testing.T) {
|
||||
func BenchmarkLoadValidators(b *testing.B) {
|
||||
const valSetSize = 100
|
||||
|
||||
cfg, err := config.ResetTestRoot("state_")
|
||||
cfg, err := config.ResetTestRoot(b.TempDir(), "state_")
|
||||
require.NoError(b, err)
|
||||
|
||||
defer os.RemoveAll(cfg.RootDir)
|
||||
|
||||
Reference in New Issue
Block a user