mirror of
https://github.com/aler9/gortsplib
synced 2025-10-05 15:16:51 +08:00
fix race condition in tests
This commit is contained in:
@@ -565,7 +565,7 @@ var cases = []struct {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"live reporter app",
|
"issue mediamtx/75",
|
||||||
[]byte("v=0\r\n" +
|
[]byte("v=0\r\n" +
|
||||||
"o=-0 0 IN IP4 127.0.0.1\r\n" +
|
"o=-0 0 IN IP4 127.0.0.1\r\n" +
|
||||||
"s=No Name\r\n" +
|
"s=No Name\r\n" +
|
||||||
|
@@ -4,6 +4,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
@@ -843,12 +844,16 @@ func TestServerSessionClose(t *testing.T) {
|
|||||||
defer stream.Close()
|
defer stream.Close()
|
||||||
|
|
||||||
var session *ServerSession
|
var session *ServerSession
|
||||||
|
connClosed := make(chan struct{})
|
||||||
|
|
||||||
s := &Server{
|
s := &Server{
|
||||||
Handler: &testServerHandler{
|
Handler: &testServerHandler{
|
||||||
onSessionOpen: func(ctx *ServerHandlerOnSessionOpenCtx) {
|
onSessionOpen: func(ctx *ServerHandlerOnSessionOpenCtx) {
|
||||||
session = ctx.Session
|
session = ctx.Session
|
||||||
},
|
},
|
||||||
|
onConnClose: func(ctx *ServerHandlerOnConnCloseCtx) {
|
||||||
|
close(connClosed)
|
||||||
|
},
|
||||||
onDescribe: func(ctx *ServerHandlerOnDescribeCtx) (*base.Response, *ServerStream, error) {
|
onDescribe: func(ctx *ServerHandlerOnDescribeCtx) (*base.Response, *ServerStream, error) {
|
||||||
return &base.Response{
|
return &base.Response{
|
||||||
StatusCode: base.StatusOK,
|
StatusCode: base.StatusOK,
|
||||||
@@ -892,6 +897,12 @@ func TestServerSessionClose(t *testing.T) {
|
|||||||
session.Close()
|
session.Close()
|
||||||
session.Close()
|
session.Close()
|
||||||
|
|
||||||
|
select {
|
||||||
|
case <-connClosed:
|
||||||
|
case <-time.After(2 * time.Second):
|
||||||
|
t.Errorf("should not happen")
|
||||||
|
}
|
||||||
|
|
||||||
_, err = writeReqReadRes(conn, base.Request{
|
_, err = writeReqReadRes(conn, base.Request{
|
||||||
Method: base.Options,
|
Method: base.Options,
|
||||||
URL: mustParseURL("rtsp://localhost:8554/"),
|
URL: mustParseURL("rtsp://localhost:8554/"),
|
||||||
|
Reference in New Issue
Block a user