Telemetry test (#258)
* Add first test for telemetry - First test for telemetry package that tests totalBytes field in downstream stats. - Add fake_analytics_service
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
package telemetrytest
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/livekit/livekit-server/pkg/telemetry"
|
||||
"github.com/livekit/livekit-server/pkg/telemetry/telemetryfakes"
|
||||
"github.com/livekit/protocol/livekit"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
type telemetryServiceFixture struct {
|
||||
sut telemetry.TelemetryService
|
||||
analytics *telemetryfakes.FakeAnalyticsService
|
||||
}
|
||||
|
||||
func createFixture() *telemetryServiceFixture {
|
||||
fixture := &telemetryServiceFixture{}
|
||||
fixture.analytics = &telemetryfakes.FakeAnalyticsService{}
|
||||
fixture.sut = telemetry.NewTelemetryService(nil, fixture.analytics)
|
||||
return fixture
|
||||
}
|
||||
|
||||
func Test_TelemetrySerice_Downstream_Stats(t *testing.T) {
|
||||
fixture := createFixture()
|
||||
|
||||
room := &livekit.Room{}
|
||||
partSID := "part1"
|
||||
participantInfo := &livekit.ParticipantInfo{Sid: partSID}
|
||||
fixture.sut.ParticipantJoined(context.Background(), room, participantInfo)
|
||||
totalBytes := 33
|
||||
fixture.sut.OnDownstreamPacket(partSID, totalBytes)
|
||||
|
||||
//call participant left to trigget sending of analytics
|
||||
fixture.sut.ParticipantLeft(context.Background(), room, participantInfo)
|
||||
|
||||
time.Sleep(time.Millisecond * 100) // wait for Update function to be called in go routine
|
||||
|
||||
require.Equal(t, 1, fixture.analytics.SendStatsCallCount())
|
||||
_, stats := fixture.analytics.SendStatsArgsForCall(0)
|
||||
require.Equal(t, 1, len(stats))
|
||||
require.Equal(t, livekit.StreamType_DOWNSTREAM, stats[0].Kind)
|
||||
require.Equal(t, totalBytes, int(stats[0].TotalBytes))
|
||||
}
|
||||
Reference in New Issue
Block a user