1
0
mirror of https://github.com/matrix-org/matrix-react-sdk.git synced 2025-07-31 13:44:28 +03:00

Improve error handling for DeviceListener (#11484)

... particularly for when it races with a client shutdown.
This commit is contained in:
Richard van der Hoff
2023-08-30 10:35:15 +01:00
committed by GitHub
parent 50160b9969
commit 6cc42b7e2e
2 changed files with 43 additions and 3 deletions

View File

@ -15,7 +15,15 @@ limitations under the License.
*/
import { Mocked, mocked } from "jest-mock";
import { MatrixEvent, Room, MatrixClient, DeviceVerificationStatus, CryptoApi, Device } from "matrix-js-sdk/src/matrix";
import {
MatrixEvent,
Room,
MatrixClient,
DeviceVerificationStatus,
CryptoApi,
Device,
ClientStoppedError,
} from "matrix-js-sdk/src/matrix";
import { logger } from "matrix-js-sdk/src/logger";
import { CrossSigningInfo } from "matrix-js-sdk/src/crypto/CrossSigning";
import { CryptoEvent } from "matrix-js-sdk/src/crypto";
@ -257,6 +265,20 @@ describe("DeviceListener", () => {
expect(mockCrypto!.isCrossSigningReady).not.toHaveBeenCalled();
});
it("correctly handles the client being stopped", async () => {
mockCrypto!.isCrossSigningReady.mockImplementation(() => {
throw new ClientStoppedError();
});
await createAndStart();
expect(logger.error).not.toHaveBeenCalled();
});
it("correctly handles other errors", async () => {
mockCrypto!.isCrossSigningReady.mockImplementation(() => {
throw new Error("blah");
});
await createAndStart();
expect(logger.error).toHaveBeenCalledTimes(1);
});
describe("set up encryption", () => {
const rooms = [{ roomId: "!room1" }, { roomId: "!room2" }] as unknown as Room[];