tests: fix race conditions (#5571)

This commit is contained in:
Alessandro Ros
2026-03-13 22:32:06 +01:00
committed by GitHub
parent 7c9023f139
commit a6856e9e58
11 changed files with 34 additions and 35 deletions
+1 -1
View File
@@ -8,7 +8,7 @@ http://localhost:8889/mystream/publish
The resulting stream will be available on path `/mystream`.
WHIP is a WebRTC extensions that allows to publish streams by using a URL, without passing through a web page. This allows to use WebRTC as a general purpose streaming protocol. If you are using a software that supports WHIP (for instance, latest versions of OBS Studio), you can publish a stream to the server by using this URL:
WHIP is a WebRTC extension that allows to publish streams by using a URL, without passing through a web page. This allows to use WebRTC as a general purpose streaming protocol. If you are using a software that supports WHIP (for instance, latest versions of OBS Studio), you can publish a stream to the server by using this URL:
```
http://localhost:8889/mystream/whip
+1 -1
View File
@@ -6,7 +6,7 @@ WebRTC is an API that makes use of a set of protocols and methods to connect two
http://localhost:8889/mystream
```
WHEP is a WebRTC extensions that allows to read streams by using a URL, without passing through a web page. This allows to use WebRTC as a general purpose streaming protocol. If you are using a software that supports WHEP, you can read a stream from the server by using this URL:
WHEP is a WebRTC extension that allows to read streams by using a URL, without passing through a web page. This allows to use WebRTC as a general purpose streaming protocol. If you are using a software that supports WHEP, you can read a stream from the server by using this URL:
```
http://localhost:8889/mystream/whep
+2 -1
View File
@@ -4,5 +4,6 @@ You can read a stream from the server by using the Go programming language and t
- [gortsplib](https://github.com/bluenviron/gortsplib) to read with RTSP.
- [gortmplib](https://github.com/bluenviron/gortmplib) to read with RTMP.
- [gohlslib](https://github.com/bluenviron/gohlslib) to read with HLS.
Both powers _MediaMTX_ itself. In the repositories of these projects there are several examples on how to connect to a server and read data.
All these power _MediaMTX_ itself. In the repositories of these projects there are several examples on how to connect to a server and read data.
+1 -1
View File
@@ -199,7 +199,7 @@ func TestAuthError(t *testing.T) {
AuthManager: &test.AuthManager{
AuthenticateImpl: func(req *auth.Request) *auth.Error {
if req.Credentials.User == "" {
return &auth.Error{AskCredentials: true}
return &auth.Error{AskCredentials: true, Wrapped: fmt.Errorf("auth error")}
}
return &auth.Error{Wrapped: fmt.Errorf("auth error")}
},
+1 -1
View File
@@ -376,7 +376,7 @@ func TestAuthError(t *testing.T) {
AuthManager: &test.AuthManager{
AuthenticateImpl: func(req *auth.Request) *auth.Error {
if req.Credentials.User == "" {
return &auth.Error{AskCredentials: true}
return &auth.Error{AskCredentials: true, Wrapped: fmt.Errorf("auth error")}
}
return &auth.Error{Wrapped: fmt.Errorf("auth error")}
},
+1 -1
View File
@@ -62,7 +62,7 @@ func TestAuthError(t *testing.T) {
AuthManager: &test.AuthManager{
AuthenticateImpl: func(req *auth.Request) *auth.Error {
if req.Credentials.User == "" {
return &auth.Error{AskCredentials: true}
return &auth.Error{AskCredentials: true, Wrapped: fmt.Errorf("auth error")}
}
return &auth.Error{Wrapped: fmt.Errorf("auth error")}
},
+1 -1
View File
@@ -105,7 +105,7 @@ func TestAuthError(t *testing.T) {
AuthManager: &test.AuthManager{
AuthenticateImpl: func(req *auth.Request) *auth.Error {
if req.Credentials.User == "" {
return &auth.Error{AskCredentials: true}
return &auth.Error{AskCredentials: true, Wrapped: fmt.Errorf("auth error")}
}
return &auth.Error{Wrapped: fmt.Errorf("auth error")}
},
+14 -3
View File
@@ -48,7 +48,7 @@ func TestToStream(t *testing.T) {
"#EXTINF:2,\n" +
"segment2.ts\n" +
"#EXTINF:2,\n" +
"segment2.ts\n" +
"segment3.ts\n" +
"#EXT-X-ENDLIST\n"))
case r.Method == http.MethodGet && r.URL.Path == "/segment1.ts":
@@ -61,6 +61,7 @@ func TestToStream(t *testing.T) {
err = w.WriteH264(track1, 2*90000, 2*90000, [][]byte{
{7, 1, 2, 3}, // SPS
{8}, // PPS
{5, 1},
})
require.NoError(t, err)
@@ -72,7 +73,7 @@ func TestToStream(t *testing.T) {
require.NoError(t, err)
err = w.WriteH264(track1, 2*90000, 2*90000, [][]byte{
{5, 1},
{5, 2},
})
require.NoError(t, err)
}
@@ -132,8 +133,18 @@ func TestToStream(t *testing.T) {
func(u *unit.Unit) error {
switch n {
case 0:
require.True(t, u.NilPayload())
require.Equal(t, unit.PayloadH264{
{7, 1, 2, 3},
{8},
{5, 1},
}, u.Payload)
require.Equal(t, time.Date(2018, 0o5, 20, 8, 17, 15, 0, time.UTC), u.NTP)
case 1:
require.Equal(t, unit.PayloadH264{
{7, 1, 2, 3},
{8},
{5, 2},
}, u.Payload)
require.Equal(t, time.Date(2018, 0o5, 20, 8, 17, 15, 0, time.UTC), u.NTP)
close(done)
default:
+1 -1
View File
@@ -539,7 +539,7 @@ func TestAuthError(t *testing.T) {
PathManager: &dummyPathManager{
findPathConfImpl: func(req defs.PathFindPathConfReq) (*conf.Path, error) {
if req.AccessRequest.Credentials.User == "" && req.AccessRequest.Credentials.Pass == "" {
return nil, &auth.Error{AskCredentials: true}
return nil, &auth.Error{AskCredentials: true, Wrapped: fmt.Errorf("auth error")}
}
return nil, &auth.Error{Wrapped: fmt.Errorf("auth error")}
+6 -6
View File
@@ -64,7 +64,7 @@ func TestServerPublish(t *testing.T) {
require.Nil(t, req.AccessRequest.CustomVerifyFunc)
if req.AccessRequest.Credentials.User == "" && req.AccessRequest.Credentials.Pass == "" {
return nil, &auth.Error{AskCredentials: true}
return nil, &auth.Error{AskCredentials: true, Wrapped: fmt.Errorf("auth error")}
}
require.Equal(t, "myuser", req.AccessRequest.Credentials.User)
@@ -74,7 +74,7 @@ func TestServerPublish(t *testing.T) {
if n == 0 {
require.False(t, ok)
n++
return nil, &auth.Error{AskCredentials: true}
return nil, &auth.Error{AskCredentials: true, Wrapped: fmt.Errorf("auth error")}
}
require.True(t, ok)
}
@@ -207,7 +207,7 @@ func TestServerRead(t *testing.T) {
require.Nil(t, req.AccessRequest.CustomVerifyFunc)
if req.AccessRequest.Credentials.User == "" && req.AccessRequest.Credentials.Pass == "" {
return defs.PathDescribeRes{Err: &auth.Error{AskCredentials: true}}
return defs.PathDescribeRes{Err: &auth.Error{AskCredentials: true, Wrapped: fmt.Errorf("auth error")}}
}
require.Equal(t, "myuser", req.AccessRequest.Credentials.User)
@@ -217,7 +217,7 @@ func TestServerRead(t *testing.T) {
if n == 0 {
require.False(t, ok)
n++
return defs.PathDescribeRes{Err: &auth.Error{AskCredentials: true}}
return defs.PathDescribeRes{Err: &auth.Error{AskCredentials: true, Wrapped: fmt.Errorf("auth error")}}
}
require.True(t, ok)
}
@@ -360,7 +360,7 @@ func TestServerRedirect(t *testing.T) {
}
if req.AccessRequest.Credentials.User == "" && req.AccessRequest.Credentials.Pass == "" {
return defs.PathDescribeRes{Err: &auth.Error{AskCredentials: true}}
return defs.PathDescribeRes{Err: &auth.Error{AskCredentials: true, Wrapped: fmt.Errorf("auth error")}}
}
require.Equal(t, "path2", req.AccessRequest.Name)
@@ -413,7 +413,7 @@ func TestAuthError(t *testing.T) {
pathManager := &test.PathManager{
DescribeImpl: func(req defs.PathDescribeReq) defs.PathDescribeRes {
if req.AccessRequest.Credentials.User == "" && req.AccessRequest.Credentials.Pass == "" {
return defs.PathDescribeRes{Err: &auth.Error{AskCredentials: true}}
return defs.PathDescribeRes{Err: &auth.Error{AskCredentials: true, Wrapped: fmt.Errorf("auth error")}}
}
return defs.PathDescribeRes{Err: &auth.Error{Wrapped: fmt.Errorf("auth error")}}
+5 -18
View File
@@ -8,7 +8,7 @@ import (
"net/http"
"net/url"
"reflect"
"sync/atomic"
"regexp"
"testing"
"time"
@@ -743,7 +743,6 @@ func TestAuthError(t *testing.T) {
"whip post",
} {
t.Run(ca, func(t *testing.T) {
n := uint64(0)
authFailed := false
s := &Server{
@@ -753,28 +752,16 @@ func TestAuthError(t *testing.T) {
PathManager: &test.PathManager{
FindPathConfImpl: func(req defs.PathFindPathConfReq) (*conf.Path, error) {
if req.AccessRequest.Credentials.User == "" && req.AccessRequest.Credentials.Pass == "" {
return nil, &auth.Error{AskCredentials: true}
return nil, &auth.Error{AskCredentials: true, Wrapped: fmt.Errorf("auth error")}
}
return nil, &auth.Error{Wrapped: fmt.Errorf("auth error")}
},
},
Parent: test.Logger(func(l logger.Level, s string, i ...any) {
switch ca {
case "whip post":
if l == logger.Info {
if atomic.AddUint64(&n, 1) == 5 {
require.Regexp(t, "failed to authenticate: auth error$", fmt.Sprintf(s, i...))
authFailed = true
}
}
default:
if l == logger.Info {
if atomic.AddUint64(&n, 1) == 2 {
require.Regexp(t, "failed to authenticate: auth error$", fmt.Sprintf(s, i...))
authFailed = true
}
if l == logger.Info {
if regexp.MustCompile("failed to authenticate: auth error$").MatchString(fmt.Sprintf(s, i...)) {
authFailed = true
}
}
}),