-
Notifications
You must be signed in to change notification settings - Fork 754
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
Use Clock interface #5907
Use Clock interface #5907
Conversation
@@ -48,13 +50,18 @@ class AttachmentEncryptionTest { | |||
inputStream = if (inputAsByteArray.isEmpty()) { | |||
inputAsByteArray.inputStream() | |||
} else { | |||
val memoryFile = MemoryFile("file" + System.currentTimeMillis(), inputAsByteArray.size) | |||
val memoryFile = MemoryFile("file_" + UUID.randomUUID(), inputAsByteArray.size) |
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.
💯
// The unique queue id will stay the same as long as this object is instanciated | ||
val queueSuffixApp = System.currentTimeMillis() | ||
// The unique queue id will stay the same as long as this object is instantiated | ||
private val queueSuffixApp = UUID.randomUUID() |
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.
👍
|
||
### Use the Clock interface, or use `measureTimeMillis` | ||
System\.currentTimeMillis\(\)===2 |
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.
💯 nice check!
override fun doWork(): Result { | ||
Timber.d("## Sync: RestartWhenNetworkOn.doWork()") | ||
val sessionId = inputData.getString(KEY_SESSION_ID) ?: return Result.failure() | ||
val syncTimeoutSeconds = inputData.getInt(KEY_SYNC_TIMEOUT_SECONDS, BackgroundSyncMode.DEFAULT_SYNC_TIMEOUT_SECONDS) | ||
val syncDelaySeconds = inputData.getInt(KEY_SYNC_DELAY_SECONDS, BackgroundSyncMode.DEFAULT_SYNC_DELAY_SECONDS) | ||
val isPeriodic = inputData.getBoolean(KEY_IS_PERIODIC, false) | ||
|
||
// Not sure how to inject a Clock here | ||
val clock = DefaultClock() |
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 would need to provide this worker via factory like https://github.com/vector-im/element-android/blob/develop/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/worker/MatrixWorkerFactory.kt#L46
I'm not sure it's worth the effort for just the clock dependency
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.
Yes, I do not think it deserves it. The factory does not exist yet, since this is the only Worker
we have on the app side (I think).
MEDIA_SAVING_3_DAYS -> System.currentTimeMillis() / 1000 - 3 * 24 * 60 * 60 | ||
MEDIA_SAVING_1_WEEK -> System.currentTimeMillis() / 1000 - 7 * 24 * 60 * 60 | ||
MEDIA_SAVING_1_MONTH -> System.currentTimeMillis() / 1000 - 30 * 24 * 60 * 60 | ||
MEDIA_SAVING_3_DAYS -> clock.epochMillis() / 1000 - 3 * 24 * 60 * 60 |
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.
not for this PR, I could imagine in the future a ClockExtensions
for these types of helpers
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.
from a static review everything looks good to me 👍
would be good to double check the keybackup (as I know that area can be a little brittle~)
…face (#4562) Sometimes move to UUID or Random numbers instead.
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.
Just some minor comments, not blocking for the merge. Also, there are some tests failure in DownloadMediaUseCaseTest because of the new param
...src/main/java/org/matrix/android/sdk/api/session/crypto/model/IncomingRequestCancellation.kt
Outdated
Show resolved
Hide resolved
...roid/src/main/java/org/matrix/android/sdk/api/session/crypto/model/IncomingRoomKeyRequest.kt
Outdated
Show resolved
Hide resolved
.../src/main/java/org/matrix/android/sdk/api/session/crypto/model/IncomingSecretShareRequest.kt
Outdated
Show resolved
Hide resolved
...sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/MXMegolmExportEncryption.kt
Show resolved
Hide resolved
...r/src/main/java/im/vector/app/features/home/room/detail/composer/MessageComposerViewState.kt
Outdated
Show resolved
Hide resolved
e35de99
to
8602cbb
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.
Just one remark, otherwise ok.
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.
SGTM, thanks
Type of change
Content
Clock
interface instead of direct usage ofSystem.currentTimeMillis()
UUID
orRandom.nextLong()
, when this is not strictly required to have a timestamp.DefaultClock
.Closes #4562
Motivation and context
Be able to speed up test! See #4562
Screenshots / GIFs
Tests
Tested devices
Reviewers
CC @ouchadam who opened the original issue.