Skip to content

Commit

Permalink
fix race condition in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aler9 committed Aug 5, 2023
1 parent f296099 commit 237d745
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/sdp/sdp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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" +
Expand Down
11 changes: 11 additions & 0 deletions server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"net"
"testing"
"time"

"github.com/stretchr/testify/require"

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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/"),
Expand Down

0 comments on commit 237d745

Please sign in to comment.