mirror of
https://github.com/livekit/livekit.git
synced 2026-05-14 22:45:20 +00:00
fix stats worker closed condition (#3965)
* fix stats worker closed condition * test * tidy
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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))
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user