Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MatrixRTC: move MatrixRTCSession logic into LocalMembershipManager #4608

Merged
28 changes: 15 additions & 13 deletions spec/unit/matrixrtc/MatrixRTCSession.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@

import { encodeBase64, EventType, MatrixClient, MatrixError, MatrixEvent, Room } from "../../../src";
import { KnownMembership } from "../../../src/@types/membership";
import { SessionMembershipData, DEFAULT_EXPIRE_DURATION } from "../../../src/matrixrtc/CallMembership";
import { DEFAULT_EXPIRE_DURATION, SessionMembershipData } from "../../../src/matrixrtc/CallMembership";
import { MembershipManager } from "../../../src/matrixrtc/MembershipManager";
import { MatrixRTCSession, MatrixRTCSessionEvent } from "../../../src/matrixrtc/MatrixRTCSession";
import { EncryptionKeysEventContent } from "../../../src/matrixrtc/types";
import { randomString } from "../../../src/randomstring";
Expand Down Expand Up @@ -235,14 +236,13 @@
});

async function testSession(membershipData: SessionMembershipData): Promise<void> {
const makeNewMembershipSpy = jest.spyOn(MembershipManager.prototype as any, "makeNewMembership");
sess = MatrixRTCSession.roomSessionForRoom(client, makeMockRoom(membershipData));

const makeNewMembershipMock = jest.spyOn(sess as any, "makeNewMembership");

sess.joinRoomSession([mockFocus], mockFocus, joinSessionConfig);
await Promise.race([sentStateEvent, new Promise((resolve) => setTimeout(resolve, 500))]);

expect(makeNewMembershipMock).toHaveBeenCalledTimes(1);
expect(makeNewMembershipSpy).toHaveBeenCalledTimes(1);

await Promise.race([sentDelayedState, new Promise((resolve) => setTimeout(resolve, 500))]);
expect(client._unstable_sendDelayedStateEvent).toHaveBeenCalledTimes(1);
Expand Down Expand Up @@ -477,23 +477,25 @@
return Promise.reject(error);
});
});
// needed to join so that myMembershipManager gets created
sess!.joinRoomSession([activeFocusConfig], activeFocus, {
membershipServerSideExpiryTimeout: 9000,
});

// needed to advance the mock timers properly
// depends on myMembershipManager being created
const scheduledDelayDisconnection = new Promise<void>((resolve) => {
const originalFn: () => void = (sess as any).scheduleDelayDisconnection;
(sess as any).scheduleDelayDisconnection = jest.fn(() => {
originalFn.call(sess);
const myMemManager = (sess as any).myMembershipManager;
const originalFn: () => void = myMemManager.scheduleDelayDisconnection;

Check failure on line 489 in spec/unit/matrixrtc/MatrixRTCSession.spec.ts

View workflow job for this annotation

GitHub Actions / Jest [unit] (Node lts/*)

MatrixRTCSession › key management › sending › doesn't re-send key immediately

TypeError: Cannot read properties of undefined (reading 'scheduleDelayDisconnection') at scheduleDelayDisconnection (spec/unit/matrixrtc/MatrixRTCSession.spec.ts:489:65) at spec/unit/matrixrtc/MatrixRTCSession.spec.ts:487:53 at asyncGeneratorStep (node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:17) at _next (node_modules/@babel/runtime/helpers/asyncToGenerator.js:17:9) at node_modules/@babel/runtime/helpers/asyncToGenerator.js:22:7 at node_modules/@babel/runtime/helpers/asyncToGenerator.js:14:12 at apply (spec/unit/matrixrtc/MatrixRTCSession.spec.ts:532:14) at apply (spec/unit/matrixrtc/MatrixRTCSession.spec.ts:437:36) at Object.testJoin (spec/unit/matrixrtc/MatrixRTCSession.spec.ts:535:23) at asyncGeneratorStep (node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:17) at _next (node_modules/@babel/runtime/helpers/asyncToGenerator.js:17:9) at node_modules/@babel/runtime/helpers/asyncToGenerator.js:22:7 at Object.<anonymous> (node_modules/@babel/runtime/helpers/asyncToGenerator.js:14:12)

Check failure on line 489 in spec/unit/matrixrtc/MatrixRTCSession.spec.ts

View workflow job for this annotation

GitHub Actions / Jest [unit] (Node lts/*)

MatrixRTCSession › key management › sending › doesn't re-send key immediately

TypeError: Cannot read properties of undefined (reading 'scheduleDelayDisconnection') at scheduleDelayDisconnection (spec/unit/matrixrtc/MatrixRTCSession.spec.ts:489:65) at spec/unit/matrixrtc/MatrixRTCSession.spec.ts:487:53 at asyncGeneratorStep (node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:17) at _next (node_modules/@babel/runtime/helpers/asyncToGenerator.js:17:9) at node_modules/@babel/runtime/helpers/asyncToGenerator.js:22:7 at node_modules/@babel/runtime/helpers/asyncToGenerator.js:14:12 at apply (spec/unit/matrixrtc/MatrixRTCSession.spec.ts:437:36) at Object.testJoin (spec/unit/matrixrtc/MatrixRTCSession.spec.ts:539:23) at asyncGeneratorStep (node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:17) at _next (node_modules/@babel/runtime/helpers/asyncToGenerator.js:17:9) at node_modules/@babel/runtime/helpers/asyncToGenerator.js:22:7 at Object.<anonymous> (node_modules/@babel/runtime/helpers/asyncToGenerator.js:14:12)

Check failure on line 489 in spec/unit/matrixrtc/MatrixRTCSession.spec.ts

View workflow job for this annotation

GitHub Actions / Jest [unit] (Node 22)

MatrixRTCSession › key management › sending › doesn't re-send key immediately

TypeError: Cannot read properties of undefined (reading 'scheduleDelayDisconnection') at scheduleDelayDisconnection (spec/unit/matrixrtc/MatrixRTCSession.spec.ts:489:65) at spec/unit/matrixrtc/MatrixRTCSession.spec.ts:487:53 at asyncGeneratorStep (node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:17) at _next (node_modules/@babel/runtime/helpers/asyncToGenerator.js:17:9) at node_modules/@babel/runtime/helpers/asyncToGenerator.js:22:7 at node_modules/@babel/runtime/helpers/asyncToGenerator.js:14:12 at apply (spec/unit/matrixrtc/MatrixRTCSession.spec.ts:532:14) at apply (spec/unit/matrixrtc/MatrixRTCSession.spec.ts:437:36) at Object.testJoin (spec/unit/matrixrtc/MatrixRTCSession.spec.ts:535:23) at asyncGeneratorStep (node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:17) at _next (node_modules/@babel/runtime/helpers/asyncToGenerator.js:17:9) at node_modules/@babel/runtime/helpers/asyncToGenerator.js:22:7 at Object.<anonymous> (node_modules/@babel/runtime/helpers/asyncToGenerator.js:14:12)

Check failure on line 489 in spec/unit/matrixrtc/MatrixRTCSession.spec.ts

View workflow job for this annotation

GitHub Actions / Jest [unit] (Node 22)

MatrixRTCSession › key management › sending › doesn't re-send key immediately

TypeError: Cannot read properties of undefined (reading 'scheduleDelayDisconnection') at scheduleDelayDisconnection (spec/unit/matrixrtc/MatrixRTCSession.spec.ts:489:65) at spec/unit/matrixrtc/MatrixRTCSession.spec.ts:487:53 at asyncGeneratorStep (node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:17) at _next (node_modules/@babel/runtime/helpers/asyncToGenerator.js:17:9) at node_modules/@babel/runtime/helpers/asyncToGenerator.js:22:7 at node_modules/@babel/runtime/helpers/asyncToGenerator.js:14:12 at apply (spec/unit/matrixrtc/MatrixRTCSession.spec.ts:437:36) at Object.testJoin (spec/unit/matrixrtc/MatrixRTCSession.spec.ts:539:23) at asyncGeneratorStep (node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:17) at _next (node_modules/@babel/runtime/helpers/asyncToGenerator.js:17:9) at node_modules/@babel/runtime/helpers/asyncToGenerator.js:22:7 at Object.<anonymous> (node_modules/@babel/runtime/helpers/asyncToGenerator.js:14:12)
myMemManager.scheduleDelayDisconnection = jest.fn(() => {
originalFn.call(myMemManager);
resolve();
});
});

sess!.joinRoomSession([activeFocusConfig], activeFocus, {
membershipServerSideExpiryTimeout: 9000,
});

expect(sess).toHaveProperty("membershipServerSideExpiryTimeout", 9000);
expect((sess as any).myMembershipManager).toHaveProperty("membershipServerSideExpiryTimeout", 9000);

Check failure on line 496 in spec/unit/matrixrtc/MatrixRTCSession.spec.ts

View workflow job for this annotation

GitHub Actions / Jest [unit] (Node lts/*)

MatrixRTCSession › joining › calls › sends a membership event with session payload when joining a call

expect(received).toHaveProperty(path, value) Matcher error: received value must not be null nor undefined Received has value: undefined at toHaveProperty (spec/unit/matrixrtc/MatrixRTCSession.spec.ts:496:59) at asyncGeneratorStep (node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:17) at _next (node_modules/@babel/runtime/helpers/asyncToGenerator.js:17:9) at node_modules/@babel/runtime/helpers/asyncToGenerator.js:22:7 at node_modules/@babel/runtime/helpers/asyncToGenerator.js:14:12 at apply (spec/unit/matrixrtc/MatrixRTCSession.spec.ts:532:14) at apply (spec/unit/matrixrtc/MatrixRTCSession.spec.ts:437:36) at Object.testJoin (spec/unit/matrixrtc/MatrixRTCSession.spec.ts:535:23) at asyncGeneratorStep (node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:17) at _next (node_modules/@babel/runtime/helpers/asyncToGenerator.js:17:9) at node_modules/@babel/runtime/helpers/asyncToGenerator.js:22:7 at Object.<anonymous> (node_modules/@babel/runtime/helpers/asyncToGenerator.js:14:12)

Check failure on line 496 in spec/unit/matrixrtc/MatrixRTCSession.spec.ts

View workflow job for this annotation

GitHub Actions / Jest [unit] (Node lts/*)

MatrixRTCSession › joining › calls › does not prefix the state key with _ for rooms that support user-owned state events

expect(received).toHaveProperty(path, value) Matcher error: received value must not be null nor undefined Received has value: undefined at toHaveProperty (spec/unit/matrixrtc/MatrixRTCSession.spec.ts:496:59) at asyncGeneratorStep (node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:17) at _next (node_modules/@babel/runtime/helpers/asyncToGenerator.js:17:9) at node_modules/@babel/runtime/helpers/asyncToGenerator.js:22:7 at node_modules/@babel/runtime/helpers/asyncToGenerator.js:14:12 at apply (spec/unit/matrixrtc/MatrixRTCSession.spec.ts:437:36) at Object.testJoin (spec/unit/matrixrtc/MatrixRTCSession.spec.ts:539:23) at asyncGeneratorStep (node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:17) at _next (node_modules/@babel/runtime/helpers/asyncToGenerator.js:17:9) at node_modules/@babel/runtime/helpers/asyncToGenerator.js:22:7 at Object.<anonymous> (node_modules/@babel/runtime/helpers/asyncToGenerator.js:14:12)

Check failure on line 496 in spec/unit/matrixrtc/MatrixRTCSession.spec.ts

View workflow job for this annotation

GitHub Actions / Jest [unit] (Node 22)

MatrixRTCSession › joining › calls › sends a membership event with session payload when joining a call

expect(received).toHaveProperty(path, value) Matcher error: received value must not be null nor undefined Received has value: undefined at toHaveProperty (spec/unit/matrixrtc/MatrixRTCSession.spec.ts:496:59) at asyncGeneratorStep (node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:17) at _next (node_modules/@babel/runtime/helpers/asyncToGenerator.js:17:9) at node_modules/@babel/runtime/helpers/asyncToGenerator.js:22:7 at node_modules/@babel/runtime/helpers/asyncToGenerator.js:14:12 at apply (spec/unit/matrixrtc/MatrixRTCSession.spec.ts:532:14) at apply (spec/unit/matrixrtc/MatrixRTCSession.spec.ts:437:36) at Object.testJoin (spec/unit/matrixrtc/MatrixRTCSession.spec.ts:535:23) at asyncGeneratorStep (node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:17) at _next (node_modules/@babel/runtime/helpers/asyncToGenerator.js:17:9) at node_modules/@babel/runtime/helpers/asyncToGenerator.js:22:7 at Object.<anonymous> (node_modules/@babel/runtime/helpers/asyncToGenerator.js:14:12)

Check failure on line 496 in spec/unit/matrixrtc/MatrixRTCSession.spec.ts

View workflow job for this annotation

GitHub Actions / Jest [unit] (Node 22)

MatrixRTCSession › joining › calls › does not prefix the state key with _ for rooms that support user-owned state events

expect(received).toHaveProperty(path, value) Matcher error: received value must not be null nor undefined Received has value: undefined at toHaveProperty (spec/unit/matrixrtc/MatrixRTCSession.spec.ts:496:59) at asyncGeneratorStep (node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:17) at _next (node_modules/@babel/runtime/helpers/asyncToGenerator.js:17:9) at node_modules/@babel/runtime/helpers/asyncToGenerator.js:22:7 at node_modules/@babel/runtime/helpers/asyncToGenerator.js:14:12 at apply (spec/unit/matrixrtc/MatrixRTCSession.spec.ts:437:36) at Object.testJoin (spec/unit/matrixrtc/MatrixRTCSession.spec.ts:539:23) at asyncGeneratorStep (node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:17) at _next (node_modules/@babel/runtime/helpers/asyncToGenerator.js:17:9) at node_modules/@babel/runtime/helpers/asyncToGenerator.js:22:7 at Object.<anonymous> (node_modules/@babel/runtime/helpers/asyncToGenerator.js:14:12)
toger5 marked this conversation as resolved.
Show resolved Hide resolved
await sendDelayedStateExceedAttempt.then(); // needed to resolve after the send attempt catches
expect(sess).toHaveProperty("membershipServerSideExpiryTimeout", 7500);
expect((sess as any).myMembershipManager).toHaveProperty("membershipServerSideExpiryTimeout", 7500);

await sendDelayedStateAttempt;
jest.advanceTimersByTime(5000);
Expand Down
Loading
Loading