Skip to content

Commit

Permalink
add timeout to test CI
Browse files Browse the repository at this point in the history
fix room test
  • Loading branch information
Yohan Totting committed Oct 23, 2023
1 parent d64693b commit b82bc74
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ jobs:
go-version: '1.20'

- name: Test
run: go test -v ./...
run: go test -v -timeout 5m ./...
40 changes: 21 additions & 19 deletions room_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ import (
)

func TestRoomCreateAndClose(t *testing.T) {
t.Parallel()
roomID := roomManager.CreateRoomID()
roomName := "test-room"

clientLeftChan := make(chan bool)

// create new room
roomOpts := DefaultRoomOptions()
roomOpts.Codecs = []string{webrtc.MimeTypeH264, webrtc.MimeTypeOpus}
testRoom, err := roomManager.NewRoom(roomID, roomName, RoomTypeLocal, roomOpts)
require.NoErrorf(t, err, "error creating new room: %v", err)

clientsLeft := 0
testRoom.OnClientLeft(func(client *Client) {
clientLeftChan <- true
clientsLeft++
})

// add a new client to room
Expand All @@ -34,36 +34,38 @@ func TestRoomCreateAndClose(t *testing.T) {
// stop client
err = testRoom.StopClient(client1.ID())
require.NoErrorf(t, err, "error stopping client: %v", err)

id = testRoom.CreateClientID()
client2, err := testRoom.AddClient(id, id, DefaultClientOptions())
require.NoErrorf(t, err, "error adding client to room: %v", err)

// stop all clients should error on not empty room
// stop all clients should error on unempty room
err = testRoom.Close()
require.EqualError(t, err, ErrRoomIsNotEmpty.Error(), "expecting error room is not empty: %v", err)

// stop other client
err = testRoom.StopClient(client2.ID())
require.NoErrorf(t, err, "error stopping client: %v", err)

allClientLeft := make(chan bool)

go func() {
for {
select {
case <-clientLeftChan:
t.Log("client left")
if len(testRoom.sfu.clients.clients) == 0 {
allClientLeft <- true
return
}
case <-time.After(5 * time.Second):
t.Log("timeout waiting for client left")
Loop:
for {
timeout, cancelTimeout := context.WithTimeout(testRoom.sfu.context, 10*time.Second)
defer cancelTimeout()
select {
case <-timeout.Done():
t.Fatal("timeout waiting for client left event")
break Loop
default:
if clientsLeft == 2 {
break Loop
}

time.Sleep(100 * time.Millisecond)
}
}()
}

require.Equal(t, 2, clientsLeft)

<-allClientLeft
err = testRoom.Close()
require.NoErrorf(t, err, "error closing room: %v", err)
}
Expand Down

0 comments on commit b82bc74

Please sign in to comment.