Skip to content

Commit

Permalink
Merge pull request #445 from ahrtr/fix_testDB_Close_PendingTx_20230330
Browse files Browse the repository at this point in the history
test: improve testDB_Close_PendingTx to reduce flaky
  • Loading branch information
ahrtr authored Mar 30, 2023
2 parents 1bc0c6b + 7b07e70 commit 3e560db
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -747,11 +747,15 @@ func testDB_Close_PendingTx(t *testing.T, writable bool) {
}

// Open update in separate goroutine.
startCh := make(chan struct{}, 1)
done := make(chan error, 1)
go func() {
startCh <- struct{}{}
err := db.Close()
done <- err
}()
// wait for the above goroutine to get scheduled.
<-startCh

// Ensure database hasn't closed.
time.Sleep(100 * time.Millisecond)
Expand All @@ -775,14 +779,13 @@ func testDB_Close_PendingTx(t *testing.T, writable bool) {
}

// Ensure database closed now.
time.Sleep(100 * time.Millisecond)
select {
case err := <-done:
if err != nil {
t.Fatalf("error from inside goroutine: %v", err)
}
default:
t.Fatal("database did not close")
case <-time.After(5 * time.Second):
t.Fatalf("database did not close")
}
}

Expand Down

0 comments on commit 3e560db

Please sign in to comment.