don't access counter directly

This commit is contained in:
Harlow Ward 2019-04-08 19:43:40 -07:00
parent d176afa7ec
commit 9d4caa05dd

View file

@ -86,7 +86,7 @@ func TestScan(t *testing.T) {
t.Errorf("callback error expected %s, got %s", "firstDatalastData", res) t.Errorf("callback error expected %s, got %s", "firstDatalastData", res)
} }
if val := ctr.counter; val != 2 { if val := ctr.Get(); val != 2 {
t.Errorf("counter error expected %d, got %d", 2, val) t.Errorf("counter error expected %d, got %d", 2, val)
} }
@ -151,7 +151,7 @@ func TestScanShard(t *testing.T) {
} }
// increments counter // increments counter
if val := ctr.counter; val != 2 { if val := ctr.Get(); val != 2 {
t.Fatalf("counter error expected %d, got %d", 2, val) t.Fatalf("counter error expected %d, got %d", 2, val)
} }
@ -324,6 +324,13 @@ type fakeCounter struct {
mu sync.Mutex mu sync.Mutex
} }
func (fc *fakeCounter) Get() int64 {
fc.mu.Lock()
defer fc.mu.Unlock()
return fc.counter
}
func (fc *fakeCounter) Add(streamName string, count int64) { func (fc *fakeCounter) Add(streamName string, count int64) {
fc.mu.Lock() fc.mu.Lock()
defer fc.mu.Unlock() defer fc.mu.Unlock()