-
-
Notifications
You must be signed in to change notification settings - Fork 592
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
Fix progress reporting for key import #4131
base: develop
Are you sure you want to change the base?
Fix progress reporting for key import #4131
Conversation
d75b11c
to
9b33030
Compare
9b33030
to
7dcce0f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few requests for cleanups... and hopefully a better test?
const backupVersion = backupInfo.version!; | ||
let success = 0; | ||
let failures = 0; | ||
const partialProgress = (stage: ImportRoomKeyProgressData): void => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems like stage
is a confusing name, when ImportRoomKeyProgressData
also has a property called stage
?
let success = 0; | ||
let failures = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could we give these clearer names, like thisChunkSuccesses
/ thisChunkFailures
?
let success = 0; | ||
let failures = 0; | ||
const partialProgress = (stage: ImportRoomKeyProgressData): void => { | ||
success = stage.successes ?? 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am led to wonder if we couldn't just change the type definition for ImportRoomKeyProgressData
to make successes
and failures
mandatory.
}); | ||
totalImported += chunk.length; | ||
totalImported += success; | ||
totalFailures += failures; | ||
} catch (e) { | ||
totalFailures += chunk.length; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this looks kinda wrong now: we could import some keys and then throw an exception, so we would end up with success + failure > total
.
Maybe:
totalFailures += chunk.length; | |
totalFailures += (chunk.length - success); |
const backupVersion = backupInfo.version!; | ||
let success = 0; | ||
let failures = 0; | ||
const partialProgress = (stage: ImportRoomKeyProgressData): void => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be clearer to inline this function? YMMV
@@ -265,6 +265,17 @@ export class RustBackupManager extends TypedEventEmitter<RustBackupCryptoEvents, | |||
}, | |||
backupVersion, | |||
); | |||
// call the progress callback one last time with the final state |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// call the progress callback one last time with the final state | |
// Call the progress callback one last time with the final state. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you also extend this comment to explain why this is required? It seems like OlmMachine.importBackedUpRoomKeys
runs the callback after each key so it's not obvious.
} | ||
}); | ||
// @ts-ignore - mock a private method for testing purpose | ||
aliceCrypto.importBackedUpRoomKeys = importMockImpl; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should definitely not do this. Doing so turns all of these tests from integration tests (where we test the whole stack, including the rust bits) into unit tests (where we are just testing the behaviour of MatrixClient
).
To be honest, it is a problem that we have existing tests that mock out CryptoApi.importBackedUpRoomKeys
but which claim to be integration tests, but that's a problem for another day.
@@ -540,6 +551,85 @@ describe.each(Object.entries(CRYPTO_BACKENDS))("megolm-keys backup (%s)", (backe | |||
expect(result.imported).toStrictEqual(expectedTotal - decryptionFailureCount); | |||
}); | |||
|
|||
it("Should report failures when decryption works but import fails", async function () { | |||
// @ts-ignore - mock a private method for testing purpose | |||
aliceCrypto.importBackedUpRoomKeys = jest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again: by mocking out importBackedUpRoomKeys
, these are unit tests rather than integration tests. We have no real evidence that the actual RustCrypto
implementation behaves the same way that these mocks do.
Could we not make up some data which causes RustCrypto.importBackedUpRoomKeys
to report a failure, without having to mock this out?
@BillCarsonFr I'm going to close this for now as it seems to be bitrotting. |
wait, sorry, it was updated last week |
Fixes element-hq/element-web#27235
Checklist
public
/exported
symbols have accurate TSDoc documentation.