Remove old regression test db in regtest mode.
The regression test mode is special in that the 'official' block test suite requires an empty database to work properly. Rather than having to manual go delete it before each test, add code to automatically delete the old regression test database when in regression test mode.
This commit is contained in:
parent
f3cd8174bb
commit
79bb334b9a
1 changed files with 32 additions and 0 deletions
|
@ -397,6 +397,34 @@ func newBlockManager(s *server) *blockManager {
|
|||
return &bm
|
||||
}
|
||||
|
||||
// removeRegressionDB removes the existing regression test database if running
|
||||
// in regression test mode and it already exists.
|
||||
func removeRegressionDB(dbPath string) error {
|
||||
// Dont do anything if not in regression test mode.
|
||||
if !cfg.RegressionTest {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Remove the old regression test database if it already exists.
|
||||
fi, err := os.Stat(dbPath)
|
||||
if err == nil {
|
||||
log.Infof("[BMGR] Removing regression test database from '%s'", dbPath)
|
||||
if fi.IsDir() {
|
||||
err := os.RemoveAll(dbPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
err := os.Remove(dbPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// loadBlockDB opens the block database and returns a handle to it.
|
||||
func loadBlockDB() (btcdb.Db, error) {
|
||||
// The database name is based on the database type.
|
||||
|
@ -406,6 +434,10 @@ func loadBlockDB() (btcdb.Db, error) {
|
|||
}
|
||||
dbPath := filepath.Join(cfg.DataDir, dbName)
|
||||
|
||||
// The regression test is special in that it needs a clean database for
|
||||
// each run, so remove it now if it already exists.
|
||||
removeRegressionDB(dbPath)
|
||||
|
||||
log.Infof("[BMGR] Loading block database from '%s'", dbPath)
|
||||
db, err := btcdb.OpenDB(cfg.DbType, dbPath)
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in a new issue