mirror of
https://github.com/aler9/rtsp-simple-server
synced 2025-09-26 19:51:26 +08:00

Discarded frames, decode errors and lost packets were logged individually, then there was a mechanism that prevented more than 1 log entry per second from being printed, resulting in inaccurate reports. Now discarded frames, decode errors and lost packets are accurately counted, and their count is printed once every second.
43 lines
632 B
Go
43 lines
632 B
Go
package counterdumper
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestCounterDumperReport(t *testing.T) {
|
|
done := make(chan struct{})
|
|
|
|
c := &CounterDumper{
|
|
OnReport: func(v uint64) {
|
|
require.Equal(t, uint64(3), v)
|
|
close(done)
|
|
},
|
|
}
|
|
c.Start()
|
|
defer c.Stop()
|
|
|
|
c.Add(2)
|
|
c.Increase()
|
|
|
|
select {
|
|
case <-done:
|
|
case <-time.After(2 * time.Second):
|
|
t.Errorf("should not happen")
|
|
}
|
|
}
|
|
|
|
func TestCounterDumperDoNotReport(t *testing.T) {
|
|
c := &CounterDumper{
|
|
OnReport: func(_ uint64) {
|
|
t.Errorf("should not happen")
|
|
},
|
|
}
|
|
c.Start()
|
|
defer c.Stop()
|
|
|
|
<-time.After(2 * time.Second)
|
|
}
|