mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-08-28 10:54:59 +00:00
fix DB-close race condition in TestTx_CommitRollback/SingleWriter
Due to lack of synchronization, this test would sometimes close the DB before terminating a transaction:
=== RUN TestTx_CommitRollback/SingleWriter
tx_test.go:132: db still has 1 active transactions; must closed before closing db
The test now waits for the goroutines to terminate before closing the DB.
This commit is contained in:
parent
b835221ded
commit
c931a3e63f
1 changed files with 8 additions and 0 deletions
|
|
@ -18,6 +18,7 @@ import (
|
|||
"fmt"
|
||||
"math"
|
||||
"math/rand"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
|
|
@ -99,17 +100,24 @@ func TestTx_CommitRollback(t *testing.T) {
|
|||
db := MustOpenDB(t)
|
||||
defer MustCloseDB(t, db)
|
||||
|
||||
var wg sync.WaitGroup
|
||||
defer wg.Wait()
|
||||
|
||||
// Start write transaction.
|
||||
ch0 := make(chan struct{})
|
||||
tx0 := MustBegin(t, db, true)
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
<-ch0
|
||||
tx0.Rollback()
|
||||
}()
|
||||
|
||||
// Start separate write transaction in different goroutine.
|
||||
ch1 := make(chan struct{})
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
tx1 := MustBegin(t, db, true)
|
||||
close(ch1)
|
||||
_ = tx1.Commit()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue