Skip to content

Commit

Permalink
Element-R: speed up slow unit test
Browse files Browse the repository at this point in the history
A couple of tests were waiting for a request that wasn't happening, so timing
out after 1.5 seconds. Let's avoid the extra slowth.

(This was introduced by changes in
#3487, but the changes in this
PR do no harm anyway)
  • Loading branch information
richvdh committed Jun 20, 2023
1 parent b77fe46 commit 136d97a
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion spec/unit/rust-crypto/rust-crypto.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,35 @@ describe("RustCrypto", () => {
rustCrypto = await makeTestRustCrypto(undefined, testData.TEST_USER_ID);
});

afterEach(() => {
jest.useRealTimers();
});

it("returns false initially", async () => {
jest.useFakeTimers();
const prom = rustCrypto.userHasCrossSigningKeys();
// the getIdentity() request should wait for a /keys/query request to complete, but times out after 1500ms
await jest.advanceTimersByTimeAsync(2000);
await expect(prom).resolves.toBe(false);
});

it("returns false if there is no cross-signing identity", async () => {
// @ts-ignore private field
const olmMachine = rustCrypto.olmMachine;

const outgoingRequests: OutgoingRequest[] = await olmMachine.outgoingRequests();
// pick out the KeysQueryRequest, and respond to it with the device keys but *no* cross-signing keys.
const req = outgoingRequests.find((r) => r instanceof KeysQueryRequest)!;
await olmMachine.markRequestAsSent(
req.id!,
req.type,
JSON.stringify({
device_keys: {
[testData.TEST_USER_ID]: { [testData.TEST_DEVICE_ID]: testData.SIGNED_TEST_DEVICE_DATA },
},
}),
);

await expect(rustCrypto.userHasCrossSigningKeys()).resolves.toBe(false);
});

Expand All @@ -381,7 +409,12 @@ describe("RustCrypto", () => {
await olmMachine.markRequestAsSent(
req.id!,
req.type,
JSON.stringify(testData.SIGNED_CROSS_SIGNING_KEYS_DATA),
JSON.stringify({
device_keys: {
[testData.TEST_USER_ID]: { [testData.TEST_DEVICE_ID]: testData.SIGNED_TEST_DEVICE_DATA },
},
...testData.SIGNED_CROSS_SIGNING_KEYS_DATA,
}),
);

// ... and we should now have cross-signing keys.
Expand Down

0 comments on commit 136d97a

Please sign in to comment.