Merge pull request #1555 from niaow/test-tx-commit-rollback-single-writer-race

Fix DB-close race condition in TestTx_CommitRollback/SingleWriter
This commit is contained in:
Nia 2021-03-29 18:13:37 -04:00 committed by GitHub
commit 71b2cb80f7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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()