mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-09-13 08:01:02 +00:00
Add rbf.DB.TxN() function and test check
This commit is contained in:
parent
c978e2242e
commit
3852ac79c4
2 changed files with 9 additions and 0 deletions
|
|
@ -100,6 +100,13 @@ func CreateDirIfNotExist(path string) {
|
|||
}
|
||||
}
|
||||
|
||||
// TxN returns the number of active transactions.
|
||||
func (db *DB) TxN() int {
|
||||
db.mu.RLock()
|
||||
defer db.mu.RUnlock()
|
||||
return len(db.txs)
|
||||
}
|
||||
|
||||
// Open opens a database with the file specified in Path.
|
||||
// Creates a new file if one does not already exist.
|
||||
func (db *DB) Open() (err error) {
|
||||
|
|
|
|||
|
|
@ -86,6 +86,8 @@ func MustCloseDB(tb testing.TB, db *rbf.DB) {
|
|||
tb.Helper()
|
||||
if err := db.Check(); err != nil && err != rbf.ErrClosed {
|
||||
tb.Fatal(err)
|
||||
} else if n := db.TxN(); n != 0 {
|
||||
tb.Fatalf("db still has %d active transactions; must closed before closing db", n)
|
||||
} else if err := db.Close(); err != nil && err != rbf.ErrClosed {
|
||||
tb.Fatal(err)
|
||||
} else if err := os.RemoveAll(db.Path); err != nil {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue