Skip to content

Commit

Permalink
Protect global n with a mutex.
Browse files Browse the repository at this point in the history
  • Loading branch information
robshakir committed Jul 29, 2024
1 parent d6c4761 commit 83b3ef0
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions gnmi/gnmi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package gnmi

import (
"context"
"sync"
"testing"
"time"

Expand Down Expand Up @@ -73,7 +74,10 @@ func TestHandleMetrics(t *testing.T) {
}

n := &gpb.Notification{}
var nMu sync.Mutex
updateFn := func(notif *gpb.Notification) error {
nMu.Lock()
defer nMu.Unlock()
n.Update = append(n.Update, notif.Update...)
return nil
}
Expand All @@ -86,6 +90,8 @@ func TestHandleMetrics(t *testing.T) {
close(g.metricCh)

time.Sleep(time.Second)
nMu.Lock()
defer nMu.Unlock()
if len(n.Update) != tc.wantCnt {
t.Errorf("missing updates: want %d got %d", tc.wantCnt, len(n.Update))
}
Expand Down

0 comments on commit 83b3ef0

Please sign in to comment.