Skip to content

Commit

Permalink
Handle nil closers (#726)
Browse files Browse the repository at this point in the history
Change the methods Done and HasBeenNotified to be able to handle a nil closer.

Also fix a flaky test.
  • Loading branch information
martinmr authored Feb 26, 2019
1 parent 291295e commit 8115aed
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 2 additions & 1 deletion managed_db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ func TestDropPrefixWithPendingTxn(t *testing.T) {
txn := db.NewTransaction(true)

var wg sync.WaitGroup
wg.Add(1)
wg.Add(2)
go func() {
defer wg.Done()
itr := txn.NewIterator(DefaultIteratorOptions)
Expand Down Expand Up @@ -464,6 +464,7 @@ func TestDropPrefixWithPendingTxn(t *testing.T) {
// Do not cancel txn.

go func() {
defer wg.Done()
time.Sleep(2 * time.Second)
require.NoError(t, db.DropPrefix([]byte("key0")))
require.NoError(t, db.DropPrefix([]byte("key00")))
Expand Down
9 changes: 9 additions & 0 deletions y/y.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ var (

// CastagnoliCrcTable is a CRC32 polynomial table
CastagnoliCrcTable = crc32.MakeTable(crc32.Castagnoli)

// Dummy channel for nil closers.
dummyCloserChan = make(chan struct{})
)

// OpenExistingFile opens an existing file, errors if it doesn't exist.
Expand Down Expand Up @@ -203,11 +206,17 @@ func (lc *Closer) Signal() {

// HasBeenClosed gets signaled when Signal() is called.
func (lc *Closer) HasBeenClosed() <-chan struct{} {
if lc == nil {
return dummyCloserChan
}
return lc.closed
}

// Done calls Done() on the WaitGroup.
func (lc *Closer) Done() {
if lc == nil {
return
}
lc.waiting.Done()
}

Expand Down

0 comments on commit 8115aed

Please sign in to comment.