Browse Source

speed up tests

pull/340/head
aler9 5 years ago
parent
commit
5d57bd8165
  1. 2
      go.mod
  2. 4
      go.sum
  3. 177
      main_clientrtsp_test.go

2
go.mod

@ -5,7 +5,7 @@ go 1.15
require ( require (
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d // indirect github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d // indirect
github.com/aler9/gortsplib v0.0.0-20210403142314-1f8d7a9ae761 github.com/aler9/gortsplib v0.0.0-20210403153532-1a229e138522
github.com/davecgh/go-spew v1.1.1 // indirect github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fsnotify/fsnotify v1.4.9 github.com/fsnotify/fsnotify v1.4.9
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51

4
go.sum

@ -2,8 +2,8 @@ github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 h1:JYp7IbQjafo
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d h1:UQZhZ2O0vMHr2cI+DC1Mbh0TJxzA3RcLoMsFw+aXw7E= github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d h1:UQZhZ2O0vMHr2cI+DC1Mbh0TJxzA3RcLoMsFw+aXw7E=
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho= github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho=
github.com/aler9/gortsplib v0.0.0-20210403142314-1f8d7a9ae761 h1:Pr4W/DxrmzxYSIf2OwCO4+6NbwWcKOasv7ZmjkNLwbY= github.com/aler9/gortsplib v0.0.0-20210403153532-1a229e138522 h1:0D22MJm5Jp8iq0KZ08/zmOon3Te0XxvIQQgIxFr+3gw=
github.com/aler9/gortsplib v0.0.0-20210403142314-1f8d7a9ae761/go.mod h1:zVCg+TQX445hh1pC5QgAuuBvvXZMWLY1XYz626dGFqY= github.com/aler9/gortsplib v0.0.0-20210403153532-1a229e138522/go.mod h1:zVCg+TQX445hh1pC5QgAuuBvvXZMWLY1XYz626dGFqY=
github.com/aler9/rtmp v0.0.0-20210403095203-3be4a5535927 h1:95mXJ5fUCYpBRdSOnLAQAdJHHKxxxJrVCiaqDi965YQ= github.com/aler9/rtmp v0.0.0-20210403095203-3be4a5535927 h1:95mXJ5fUCYpBRdSOnLAQAdJHHKxxxJrVCiaqDi965YQ=
github.com/aler9/rtmp v0.0.0-20210403095203-3be4a5535927/go.mod h1:vzuE21rowz+lT1NGsWbreIvYulgBpCGnQyeTyFblUHc= github.com/aler9/rtmp v0.0.0-20210403095203-3be4a5535927/go.mod h1:vzuE21rowz+lT1NGsWbreIvYulgBpCGnQyeTyFblUHc=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=

177
main_clientrtsp_test.go

@ -448,91 +448,70 @@ func TestClientRTSPAutomaticProtocol(t *testing.T) {
} }
func TestClientRTSPPublisherOverride(t *testing.T) { func TestClientRTSPPublisherOverride(t *testing.T) {
t.Run("enabled", func(t *testing.T) { for _, ca := range []string{
p, ok := testProgram("rtmpDisable: yes\n") "enabled",
require.Equal(t, true, ok) "disabled",
defer p.close() } {
t.Run(ca, func(t *testing.T) {
source1, err := newContainer("ffmpeg", "source1", []string{ conf := "rtmpDisable: yes\n" +
"-re", "protocols: [tcp]\n"
"-stream_loop", "-1", if ca == "disabled" {
"-i", "emptyvideo.mkv", conf += "paths:\n" +
"-c", "copy", " all:\n" +
"-f", "rtsp", " disablePublisherOverride: yes\n"
"rtsp://" + ownDockerIP + ":8554/teststream", }
}) p, ok := testProgram(conf)
require.NoError(t, err) require.Equal(t, true, ok)
defer source1.close() defer p.close()
time.Sleep(1 * time.Second)
source2, err := newContainer("ffmpeg", "source2", []string{
"-re",
"-stream_loop", "-1",
"-i", "emptyvideo.mkv",
"-c", "copy",
"-f", "rtsp",
"rtsp://" + ownDockerIP + ":8554/teststream",
})
require.NoError(t, err)
defer source2.close()
time.Sleep(1 * time.Second) track, err := gortsplib.NewTrackH264(68, []byte{0x01, 0x02, 0x03, 0x04}, []byte{0x01, 0x02, 0x03, 0x04})
require.NoError(t, err)
dest, err := newContainer("ffmpeg", "dest", []string{ s1, err := gortsplib.DialPublish("rtsp://"+ownDockerIP+":8554/teststream",
"-i", "rtsp://" + ownDockerIP + ":8554/teststream", gortsplib.Tracks{track})
"-vframes", "1", require.NoError(t, err)
"-f", "image2", defer s1.Close()
"-y", "/dev/null",
})
require.NoError(t, err)
defer dest.close()
require.Equal(t, 0, dest.wait())
})
t.Run("disabled", func(t *testing.T) { s2, err := gortsplib.DialPublish("rtsp://"+ownDockerIP+":8554/teststream",
p, ok := testProgram("rtmpDisable: yes\n" + gortsplib.Tracks{track})
"paths:\n" + if ca == "enabled" {
" all:\n" + require.NoError(t, err)
" disablePublisherOverride: yes\n") defer s2.Close()
require.Equal(t, true, ok) } else {
defer p.close() require.Error(t, err)
}
source1, err := newContainer("ffmpeg", "source1", []string{ d1, err := gortsplib.DialRead("rtsp://" + ownDockerIP + ":8554/teststream")
"-re", require.NoError(t, err)
"-stream_loop", "-1", defer d1.Close()
"-i", "emptyvideo.mkv",
"-c", "copy", recv := make(chan struct{})
"-f", "rtsp", d1.ReadFrames(func(trackID int, streamType base.StreamType, payload []byte) {
"rtsp://" + ownDockerIP + ":8554/teststream", if ca == "enabled" {
}) require.Equal(t, []byte{0x05, 0x06, 0x07, 0x08}, payload)
require.NoError(t, err) } else {
defer source1.close() require.Equal(t, []byte{0x01, 0x02, 0x03, 0x04}, payload)
}
close(recv)
})
time.Sleep(1 * time.Second) err = s1.WriteFrame(track.ID, gortsplib.StreamTypeRTP,
[]byte{0x01, 0x02, 0x03, 0x04})
if ca == "enabled" {
require.Error(t, err)
} else {
require.NoError(t, err)
}
source2, err := newContainer("ffmpeg", "source2", []string{ if ca == "enabled" {
"-re", err = s2.WriteFrame(track.ID, gortsplib.StreamTypeRTP,
"-stream_loop", "-1", []byte{0x05, 0x06, 0x07, 0x08})
"-i", "emptyvideo.mkv", require.NoError(t, err)
"-c", "copy", }
"-f", "rtsp",
"rtsp://" + ownDockerIP + ":8554/teststream",
})
require.NoError(t, err)
defer source2.close()
require.NotEqual(t, 0, source2.wait())
dest, err := newContainer("ffmpeg", "dest", []string{ <-recv
"-i", "rtsp://" + ownDockerIP + ":8554/teststream",
"-vframes", "1",
"-f", "image2",
"-y", "/dev/null",
}) })
require.NoError(t, err) }
defer dest.close()
require.Equal(t, 0, dest.wait())
})
} }
func TestClientRTSPNonCompliantFrameSize(t *testing.T) { func TestClientRTSPNonCompliantFrameSize(t *testing.T) {
@ -550,6 +529,7 @@ func TestClientRTSPNonCompliantFrameSize(t *testing.T) {
v := gortsplib.StreamProtocolTCP v := gortsplib.StreamProtocolTCP
return &v return &v
}(), }(),
ReadBufferSize: 4500,
} }
source, err := conf.DialPublish("rtsp://"+ownDockerIP+":8554/teststream", source, err := conf.DialPublish("rtsp://"+ownDockerIP+":8554/teststream",
@ -557,14 +537,27 @@ func TestClientRTSPNonCompliantFrameSize(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
defer source.Close() defer source.Close()
buf := bytes.Repeat([]byte{0x01, 0x02, 0x03, 0x04, 0x05}, 4096/5) dest, err := conf.DialRead("rtsp://" + ownDockerIP + ":8554/teststream")
err = source.WriteFrame(track.ID, gortsplib.StreamTypeRTP, buf)
require.NoError(t, err) require.NoError(t, err)
defer dest.Close()
time.Sleep(100 * time.Millisecond) input := bytes.Repeat([]byte{0x01, 0x02, 0x03, 0x04, 0x05}, 4096/5)
err = source.WriteFrame(track.ID, gortsplib.StreamTypeRTP, buf) recvDone := make(chan struct{})
recvErr := dest.ReadFrames(func(trackID int, streamType gortsplib.StreamType, payload []byte) {
require.Equal(t, gortsplib.StreamTypeRTP, streamType)
require.Equal(t, input, payload)
close(recvDone)
})
err = source.WriteFrame(track.ID, gortsplib.StreamTypeRTP, input)
require.NoError(t, err) require.NoError(t, err)
select {
case <-recvDone:
case err := <-recvErr:
t.Error(err)
}
}) })
t.Run("proxy", func(t *testing.T) { t.Run("proxy", func(t *testing.T) {
@ -596,7 +589,8 @@ func TestClientRTSPNonCompliantFrameSize(t *testing.T) {
"rtspPort: 8555\n" + "rtspPort: 8555\n" +
"paths:\n" + "paths:\n" +
" teststream:\n" + " teststream:\n" +
" source: rtsp://" + ownDockerIP + ":8554/teststream\n") " source: rtsp://" + ownDockerIP + ":8554/teststream\n" +
" sourceProtocol: tcp\n")
require.Equal(t, true, ok) require.Equal(t, true, ok)
defer p2.close() defer p2.close()
@ -606,21 +600,22 @@ func TestClientRTSPNonCompliantFrameSize(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
defer dest.Close() defer dest.Close()
done := make(chan struct{}) input := bytes.Repeat([]byte{0x01, 0x02, 0x03, 0x04, 0x05}, 4096/5)
cerr := dest.ReadFrames(func(trackID int, typ gortsplib.StreamType, buf []byte) {
if typ == gortsplib.StreamTypeRTP { recvDone := make(chan struct{})
close(done) recvErr := dest.ReadFrames(func(trackID int, streamType gortsplib.StreamType, payload []byte) {
} require.Equal(t, gortsplib.StreamTypeRTP, streamType)
require.Equal(t, input, payload)
close(recvDone)
}) })
buf := bytes.Repeat([]byte{0x01, 0x02, 0x03, 0x04, 0x05}, 4096/5) err = source.WriteFrame(track.ID, gortsplib.StreamTypeRTP, input)
err = source.WriteFrame(track.ID, gortsplib.StreamTypeRTP, buf)
require.NoError(t, err) require.NoError(t, err)
select { select {
case err := <-cerr: case <-recvDone:
case err := <-recvErr:
t.Error(err) t.Error(err)
case <-done:
} }
}) })
} }

Loading…
Cancel
Save