mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-09-11 15:21:02 +00:00
Fix a few data races
This commit is contained in:
parent
f59452a7e7
commit
5d43d414f7
2 changed files with 14 additions and 7 deletions
|
|
@ -5,6 +5,7 @@ import (
|
|||
"io"
|
||||
"io/ioutil"
|
||||
gohttp "net/http"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
|
|
@ -37,9 +38,10 @@ func TestTranslateStore_Reader(t *testing.T) {
|
|||
return 0, nil
|
||||
}
|
||||
}
|
||||
var closeInvoked bool
|
||||
closeInvoked := atomic.Value{}
|
||||
closeInvoked.Store(false)
|
||||
mrc.CloseFunc = func() error {
|
||||
closeInvoked = true
|
||||
closeInvoked.Store(true)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
@ -85,7 +87,7 @@ func TestTranslateStore_Reader(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if !closeInvoked {
|
||||
if !closeInvoked.Load().(bool) {
|
||||
t.Fatal("expected server close")
|
||||
}
|
||||
})
|
||||
|
|
@ -100,9 +102,12 @@ func TestTranslateStore_Reader(t *testing.T) {
|
|||
<-done
|
||||
return 0, io.EOF
|
||||
}
|
||||
var closeInvoked bool
|
||||
|
||||
closeInvoked := atomic.Value{}
|
||||
closeInvoked.Store(false)
|
||||
|
||||
mrc.CloseFunc = func() error {
|
||||
closeInvoked = true
|
||||
closeInvoked.Store(true)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
@ -127,7 +132,7 @@ func TestTranslateStore_Reader(t *testing.T) {
|
|||
// Cancel the context and check if server is closed.
|
||||
cancel()
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
if !closeInvoked {
|
||||
if !closeInvoked.Load().(bool) {
|
||||
t.Fatal("expected server-side close")
|
||||
}
|
||||
})
|
||||
|
|
|
|||
|
|
@ -306,11 +306,13 @@ func (s *TranslateFile) replicate(ctx context.Context) error {
|
|||
} else if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
s.mu.Lock()
|
||||
// Write to local store.
|
||||
if err := s.appendEntry(&entry); err != nil {
|
||||
s.mu.Unlock()
|
||||
return err
|
||||
}
|
||||
s.mu.Unlock()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue