mirror of
https://github.com/aler9/gortsplib
synced 2025-10-05 07:06:58 +08:00
fix race condition in tests
This commit is contained in:
@@ -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/"),
|
||||
|
Reference in New Issue
Block a user