mirror of
https://github.com/livekit/livekit.git
synced 2026-10-23 13:02:53 +00:00
Fix data race on global logger in sfu downtrack integration test (#5036)
TestDownTrackResumesAfterBandwidthPause called logger.InitFromConfig (SetLogger) mid-run while the hwstats CPU monitor goroutine, started by prometheus.Init in forwardstats_test, read the same non-atomic logger package globals. go test -race flagged the write-vs-read and failed CI. Set the global logger once in TestMain, before any test starts that goroutine, and drop the per-test InitFromConfig. Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
1 parent
0a94c9cf9c
commit
a8afbd69bd
1 file changed
+10
-1
@@ -45,6 +45,7 @@ import (
|
||||
"encoding/binary"
|
||||
"io"
|
||||
"math"
|
||||
"os"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
@@ -77,6 +78,15 @@ import (
|
||||
"github.com/livekit/livekit-server/pkg/testutils/vnettest"
|
||||
)
|
||||
|
||||
// TestMain sets the global logger once, before any test starts a background
|
||||
// goroutine that reads it (prometheus.Init starts an hwstats CPU monitor that
|
||||
// logs via the global logger). Calling logger.SetLogger from inside a test while
|
||||
// that goroutine runs is a data race on the logger package globals.
|
||||
func TestMain(m *testing.M) {
|
||||
logger.InitFromConfig(&logger.Config{Level: "debug"}, "sfu-test")
|
||||
os.Exit(m.Run())
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// packet capture on the far side
|
||||
// -----------------------------------------------------------------------------
|
||||
@@ -1135,7 +1145,6 @@ func TestDownTrackResumesAfterBandwidthPause(t *testing.T) {
|
||||
}
|
||||
|
||||
func testResumeAfterBandwidthPause(t *testing.T, allowPause bool) {
|
||||
logger.InitFromConfig(&logger.Config{Level: "debug"}, t.Name())
|
||||
const (
|
||||
layer0Bps = 80_000
|
||||
layer1Bps = 170_000
|
||||
|
||||
Reference in new issue
Block a user