fix race condition in tests

This commit is contained in:
aler9
2023-08-02 18:44:31 +02:00
committed by Alessandro Ros
parent 33bc1c874b
commit 17acec3f0d
2 changed files with 12 additions and 1 deletions

View File

@@ -565,7 +565,7 @@ var cases = []struct {
},
},
{
"live reporter app",
"issue mediamtx/75",
[]byte("v=0\r\n" +
"o=-0 0 IN IP4 127.0.0.1\r\n" +
"s=No Name\r\n" +

View File

@@ -4,6 +4,7 @@ import (
"fmt"
"net"
"testing"
"time"
"github.com/stretchr/testify/require"
@@ -843,12 +844,16 @@ func TestServerSessionClose(t *testing.T) {
defer stream.Close()
var session *ServerSession
connClosed := make(chan struct{})
s := &Server{
Handler: &testServerHandler{
onSessionOpen: func(ctx *ServerHandlerOnSessionOpenCtx) {
session = ctx.Session
},
onConnClose: func(ctx *ServerHandlerOnConnCloseCtx) {
close(connClosed)
},
onDescribe: func(ctx *ServerHandlerOnDescribeCtx) (*base.Response, *ServerStream, error) {
return &base.Response{
StatusCode: base.StatusOK,
@@ -892,6 +897,12 @@ func TestServerSessionClose(t *testing.T) {
session.Close()
session.Close()
select {
case <-connClosed:
case <-time.After(2 * time.Second):
t.Errorf("should not happen")
}
_, err = writeReqReadRes(conn, base.Request{
Method: base.Options,
URL: mustParseURL("rtsp://localhost:8554/"),