From 9d4caa05dd85f89f580f92c310f7483562c89028 Mon Sep 17 00:00:00 2001 From: Harlow Ward Date: Mon, 8 Apr 2019 19:43:40 -0700 Subject: [PATCH] don't access counter directly --- consumer_test.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/consumer_test.go b/consumer_test.go index f1edcd9..caaa04b 100644 --- a/consumer_test.go +++ b/consumer_test.go @@ -86,7 +86,7 @@ func TestScan(t *testing.T) { 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) } @@ -151,7 +151,7 @@ func TestScanShard(t *testing.T) { } // increments counter - if val := ctr.counter; val != 2 { + if val := ctr.Get(); val != 2 { t.Fatalf("counter error expected %d, got %d", 2, val) } @@ -324,6 +324,13 @@ type fakeCounter struct { 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) { fc.mu.Lock() defer fc.mu.Unlock()