44 lines
1.8 KiB
Go
44 lines
1.8 KiB
Go
package service
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"hyapp/services/room-service/internal/room/command"
|
|
"hyapp/services/room-service/internal/room/state"
|
|
)
|
|
|
|
func TestReplayMicHeartbeatSkipsStaleMissingSeat(t *testing.T) {
|
|
current := state.NewRoomState("room-replay-stale-heartbeat", 7101, 8, "voice")
|
|
current.OnlineUsers[7101] = &state.RoomUserState{UserID: 7101, Role: "owner", JoinedAtMS: 1000, LastSeenAtMS: 1000}
|
|
|
|
if err := replay(current, &command.MicHeartbeat{
|
|
Base: command.Base{ActorID: 7101, Room: current.RoomID, SentAtMS: 2000},
|
|
TargetUserID: 7101,
|
|
MicSessionID: "mic-old",
|
|
}, 2000); err != nil {
|
|
t.Fatalf("stale heartbeat without seat must be skipped: %v", err)
|
|
}
|
|
if current.Version != 0 || current.OnlineUsers[7101].LastSeenAtMS != 1000 {
|
|
t.Fatalf("stale heartbeat must not mutate state, version=%d user=%+v", current.Version, current.OnlineUsers[7101])
|
|
}
|
|
}
|
|
|
|
func TestReplayMicHeartbeatSkipsStaleSession(t *testing.T) {
|
|
current := state.NewRoomState("room-replay-stale-session", 7201, 8, "voice")
|
|
current.OnlineUsers[7201] = &state.RoomUserState{UserID: 7201, Role: "owner", JoinedAtMS: 1000, LastSeenAtMS: 1000}
|
|
current.MicSeats[0].UserID = 7201
|
|
current.MicSeats[0].PublishState = state.MicPublishPending
|
|
current.MicSeats[0].MicSessionID = "mic-new"
|
|
|
|
if err := replay(current, &command.MicHeartbeat{
|
|
Base: command.Base{ActorID: 7201, Room: current.RoomID, SentAtMS: 2000},
|
|
TargetUserID: 7201,
|
|
MicSessionID: "mic-old",
|
|
}, 2000); err != nil {
|
|
t.Fatalf("stale heartbeat for replaced session must be skipped: %v", err)
|
|
}
|
|
if current.Version != 0 || current.MicSeats[0].MicHeartbeatAtMS != 0 || current.OnlineUsers[7201].LastSeenAtMS != 1000 {
|
|
t.Fatalf("stale heartbeat must not refresh pending/replaced session, version=%d seat=%+v user=%+v", current.Version, current.MicSeats[0], current.OnlineUsers[7201])
|
|
}
|
|
}
|