fix stats worker closed condition (#3965)

* fix stats worker closed condition

* test

* tidy
This commit is contained in:
Paul Wells
2025-09-29 02:51:58 -07:00
committed by GitHub
parent 3d73703152
commit b3ee219ccb
2 changed files with 20 additions and 1 deletions
+1 -1
View File
@@ -162,7 +162,7 @@ func (s *StatsWorker) Close(guard *ReferenceGuard) bool {
func (s *StatsWorker) Closed(guard *ReferenceGuard) bool {
s.lock.Lock()
defer s.lock.Unlock()
if !s.closedAt.IsZero() {
if s.closedAt.IsZero() {
s.refCount.Activate(guard)
return false
}
+19
View File
@@ -0,0 +1,19 @@
package telemetry
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestStatsWorker(t *testing.T) {
t.Run("reference counted close works", func(t *testing.T) {
var g0, g1 ReferenceGuard
w := newStatsWorker(t.Context(), nil, "", "", "", "", &g0)
require.False(t, w.Closed(&g1))
require.False(t, w.Close(&g0))
require.False(t, w.Closed(&g1))
require.True(t, w.Close(&g1))
require.True(t, w.Closed(&g1))
})
}