Skip to content

Commit b2b8bf5

Browse files
committed
Add test for disinvite in clusters, improve existing tests.
1 parent 51bdef1 commit b2b8bf5

2 files changed

Lines changed: 86 additions & 8 deletions

File tree

server/backend_server_test.go

Lines changed: 77 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ func RunTestBackendServer_RoomDisinvite(ctx context.Context, t *testing.T) {
529529
testDefaultUserId,
530530
},
531531
SessionIds: []api.RoomSessionId{
532-
api.RoomSessionId(fmt.Sprintf("%s-%s"+roomId, hello.Hello.SessionId)),
532+
api.RoomSessionId(fmt.Sprintf("%s-%s", roomId, hello.Hello.SessionId)),
533533
},
534534
Properties: roomProperties,
535535
},
@@ -555,9 +555,16 @@ func RunTestBackendServer_RoomDisinvite(ctx context.Context, t *testing.T) {
555555
}
556556
if message, ok := client.RunUntilRoomlistDisinvite(ctx); ok {
557557
assert.Equal(roomId, message.RoomId)
558+
assert.Equal(api.DisinviteReasonDisinvited, message.Reason)
559+
}
560+
if message, ok := client.RunUntilMessageOrClosed(ctx); ok && message != nil {
561+
// The client might receive a second disinvite message as both the userid and the session id were disinvited.
562+
if message, ok := checkMessageRoomlistDisinvite(t, message); ok {
563+
assert.Equal(roomId, message.RoomId)
564+
assert.Equal(api.DisinviteReasonDisinvited, message.Reason)
565+
}
566+
client.RunUntilClosed(ctx)
558567
}
559-
560-
client.RunUntilClosed(ctx)
561568
}
562569

563570
func TestBackendServer_RoomDisinviteDifferentRooms(t *testing.T) {
@@ -591,7 +598,7 @@ func TestBackendServer_RoomDisinviteDifferentRooms(t *testing.T) {
591598
testDefaultUserId,
592599
},
593600
SessionIds: []api.RoomSessionId{
594-
api.RoomSessionId(fmt.Sprintf("%s-%s"+roomId1, hello1.Hello.SessionId)),
601+
api.RoomSessionId(fmt.Sprintf("%s-%s", roomId1, hello1.Hello.SessionId)),
595602
},
596603
},
597604
}
@@ -610,12 +617,20 @@ func TestBackendServer_RoomDisinviteDifferentRooms(t *testing.T) {
610617
}
611618
if message, ok := client1.RunUntilRoomlistDisinvite(ctx); ok {
612619
assert.Equal(roomId1, message.RoomId)
620+
assert.Equal(api.DisinviteReasonDisinvited, message.Reason)
621+
}
622+
if message, ok := client1.RunUntilMessageOrClosed(ctx); ok && message != nil {
623+
// The client might receive a second disinvite message as both the userid and the session id were disinvited.
624+
if message, ok := checkMessageRoomlistDisinvite(t, message); ok {
625+
assert.Equal(roomId1, message.RoomId)
626+
assert.Equal(api.DisinviteReasonDisinvited, message.Reason)
627+
}
628+
client1.RunUntilClosed(ctx)
613629
}
614-
615-
client1.RunUntilClosed(ctx)
616630

617631
if message, ok := client2.RunUntilRoomlistDisinvite(ctx); ok {
618632
assert.Equal(roomId1, message.RoomId)
633+
assert.Equal(api.DisinviteReasonDisinvited, message.Reason)
619634
}
620635

621636
msg = &talk.BackendServerRoomRequest{
@@ -639,6 +654,62 @@ func TestBackendServer_RoomDisinviteDifferentRooms(t *testing.T) {
639654
}
640655
}
641656

657+
func TestBackendServer_RoomDisinviteClustered(t *testing.T) {
658+
t.Parallel()
659+
logger := logtest.NewLoggerForTest(t)
660+
ctx := log.NewLoggerContext(t.Context(), logger)
661+
require := require.New(t)
662+
assert := assert.New(t)
663+
_, _, hub1, hub2, server1, server2 := CreateBackendServerWithClusteringForTest(t)
664+
665+
ctx, cancel := context.WithTimeout(ctx, testTimeout)
666+
defer cancel()
667+
668+
client1, hello1 := NewTestClientWithHello(ctx, t, server1, hub1, testDefaultUserId+"1")
669+
defer client1.CloseWithBye()
670+
client2, hello2 := NewTestClientWithHello(ctx, t, server2, hub2, testDefaultUserId+"2")
671+
defer client2.CloseWithBye()
672+
673+
// Join room by id.
674+
roomId := "test-room1"
675+
MustSucceed2(t, client1.JoinRoom, ctx, roomId)
676+
MustSucceed2(t, client2.JoinRoom, ctx, roomId)
677+
WaitForUsersJoined(ctx, t, client1, hello1, client2, hello2)
678+
679+
msg := &talk.BackendServerRoomRequest{
680+
Type: "disinvite",
681+
Disinvite: &talk.BackendRoomDisinviteRequest{
682+
SessionIds: []api.RoomSessionId{
683+
api.RoomSessionId(fmt.Sprintf("%s-%s", roomId, hello2.Hello.SessionId)),
684+
},
685+
},
686+
}
687+
688+
data, err := json.Marshal(msg)
689+
require.NoError(err)
690+
res, err := performBackendRequest(server1.URL+"/api/v1/room/"+roomId, data)
691+
require.NoError(err)
692+
defer res.Body.Close()
693+
body, err := io.ReadAll(res.Body)
694+
assert.NoError(err)
695+
assert.Equal(http.StatusOK, res.StatusCode, "Expected successful request, got %s", string(body))
696+
697+
if message, ok := client1.RunUntilRoomlistUpdate(ctx); ok {
698+
assert.Equal(roomId, message.RoomId)
699+
}
700+
701+
if message, ok := client2.RunUntilRoomlistUpdate(ctx); ok {
702+
assert.Equal(roomId, message.RoomId)
703+
}
704+
if message, ok := client2.RunUntilRoomlistDisinvite(ctx); ok {
705+
assert.Equal(roomId, message.RoomId)
706+
assert.Equal(api.DisinviteReasonDisinvited, message.Reason)
707+
}
708+
client2.RunUntilClosed(ctx)
709+
710+
client1.RunUntilLeft(ctx, hello2.Hello)
711+
}
712+
642713
func TestBackendServer_RoomUpdate(t *testing.T) {
643714
t.Parallel()
644715
for _, backend := range eventstest.EventBackendsForTest {

server/room_test.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import (
3535
"github.com/stretchr/testify/assert"
3636
"github.com/stretchr/testify/require"
3737

38+
"github.com/strukturag/nextcloud-spreed-signaling/api"
3839
"github.com/strukturag/nextcloud-spreed-signaling/log"
3940
logtest "github.com/strukturag/nextcloud-spreed-signaling/log/test"
4041
"github.com/strukturag/nextcloud-spreed-signaling/talk"
@@ -220,14 +221,20 @@ func TestRoom_Delete(t *testing.T) {
220221
// Ordering should be "leave room", "disinvited".
221222
checkMessageRoomId(t, message1, "")
222223
if message2, ok := client.RunUntilMessage(ctx); ok {
223-
checkMessageRoomlistDisinvite(t, message2)
224+
if msg, ok := checkMessageRoomlistDisinvite(t, message2); ok {
225+
assert.Equal(roomId, msg.RoomId)
226+
assert.Equal(api.DisinviteReasonDeleted, msg.Reason)
227+
}
224228
}
225229
if !client.RunUntilClosed(ctx) {
226230
return
227231
}
228232
} else {
229233
// Ordering should be "disinvited", "leave room".
230-
checkMessageRoomlistDisinvite(t, message1)
234+
if msg, ok := checkMessageRoomlistDisinvite(t, message1); ok {
235+
assert.Equal(roomId, msg.RoomId)
236+
assert.Equal(api.DisinviteReasonDeleted, msg.Reason)
237+
}
231238
// The connection should get closed after the "disinvited".
232239
// However due to the asynchronous processing, the "leave room" message might be received before.
233240
if message2, ok := client.RunUntilMessageOrClosed(ctx); ok && message2 != nil {

0 commit comments

Comments
 (0)