diff --git a/pkg/sfu/downtrack_downstream_integration_test.go b/pkg/sfu/downtrack_downstream_integration_test.go index 99f1c3d0f..e16ecd765 100644 --- a/pkg/sfu/downtrack_downstream_integration_test.go +++ b/pkg/sfu/downtrack_downstream_integration_test.go @@ -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