-
Notifications
You must be signed in to change notification settings - Fork 465
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
integration-tests: Add test for openvidu active entities fixer
- Loading branch information
1 parent
c2d7f01
commit a01b1e2
Showing
1 changed file
with
97 additions
and
0 deletions.
There are no files selected for viewing
97 changes: 97 additions & 0 deletions
97
openvidu-test-integration/tests/openvidu-active-entities-fixer.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import { | ||
joinParticipantToRoom, | ||
killProcess, | ||
sleep, | ||
startComposeContainer, | ||
startLocalDeployment, | ||
stopComposeContainer, | ||
stopLocalDeployment | ||
} from "./utils/helper"; | ||
import { MongoService } from "./utils/mongodb"; | ||
import { EntityType } from "./utils/types"; | ||
|
||
describe("OpenVidu active entities fixer", () => { | ||
const mongoService = MongoService.getInstance(); | ||
|
||
beforeEach(async () => { | ||
await startLocalDeployment(); | ||
}, 60000); // 1 minute | ||
|
||
afterEach(() => { | ||
stopLocalDeployment(); | ||
}, 60000); // 1 minute | ||
|
||
it("should fix fake active entities in MongoDB", async () => { | ||
console.log("Joining participant to room..."); | ||
const roomName = "TestRoom"; | ||
const participantIdentity = "TestParticipant1"; | ||
const pid = joinParticipantToRoom(participantIdentity, roomName); | ||
await sleep(5); | ||
|
||
const roomStartedEvent = await mongoService.findStartEvent(EntityType.ROOM, roomName); | ||
if (!roomStartedEvent) { | ||
throw new Error("ROOM_CREATED event not found"); | ||
} | ||
|
||
const participantActiveEvent = await mongoService.findStartEvent(EntityType.PARTICIPANT, participantIdentity); | ||
if (!participantActiveEvent) { | ||
throw new Error("PARTICIPANT_ACTIVE event not found"); | ||
} | ||
|
||
const roomId = roomStartedEvent.room.sid; | ||
const participantId = participantActiveEvent.participant_id; | ||
|
||
stopComposeContainer("openvidu"); | ||
killProcess(pid); | ||
await sleep(5); | ||
startComposeContainer("openvidu"); | ||
|
||
// Check if there is a fake close event for room and participant in MongoDB | ||
// and the active entities are removed | ||
let roomEndedEvent; | ||
let participantLeftEvent; | ||
let isRoomActive: boolean; | ||
let isParticipantActive: boolean; | ||
|
||
do { | ||
console.log("Waiting for fake close events in MongoDB..."); | ||
await sleep(10); | ||
roomEndedEvent = await mongoService.findCloseEvent(EntityType.ROOM, roomId); | ||
participantLeftEvent = await mongoService.findCloseEvent(EntityType.PARTICIPANT, participantId); | ||
isRoomActive = await mongoService.isActiveEntity(roomId); | ||
isParticipantActive = await mongoService.isActiveEntity(participantId); | ||
} while (!roomEndedEvent || !participantLeftEvent || isRoomActive || isParticipantActive); | ||
|
||
// Check properties of fake ROOM_ENDED event | ||
expect(isRoomActive).toBeFalsy(); | ||
expect(roomEndedEvent).not.toBeNull(); | ||
expect(roomEndedEvent).toMatchObject({ | ||
room_id: roomId, | ||
room: { | ||
sid: roomId, | ||
name: roomName, | ||
creation_time: roomStartedEvent.room.creation_time | ||
} | ||
}); | ||
expect(roomEndedEvent!.timestamp.seconds).toBeGreaterThan(roomStartedEvent.room.creation_time); | ||
expect(roomEndedEvent!.openvidu_expire_at).toBeDefined(); | ||
|
||
// Check properties of fake PARTICIPANT_LEFT event | ||
expect(isParticipantActive).toBeFalsy(); | ||
expect(participantLeftEvent).not.toBeNull(); | ||
expect(participantLeftEvent).toMatchObject({ | ||
room_id: roomId, | ||
room: { | ||
sid: roomId | ||
}, | ||
participant_id: participantId, | ||
participant: { | ||
sid: participantId, | ||
identity: participantIdentity, | ||
joined_at: participantActiveEvent.participant.joined_at | ||
} | ||
}); | ||
expect(participantLeftEvent!.timestamp.seconds).toBeGreaterThan(participantActiveEvent.participant.joined_at); | ||
expect(participantLeftEvent!.openvidu_expire_at).toBeDefined(); | ||
}, 300000); // 5 minutes | ||
}); |